Skip to content

Conversation

@apoelstra
Copy link

According to this MDN document there is an ECMAScript extension to ISO 8601 to allow signed durations by putting a + or - before the ISO duration format.

Internally we support signed durations -- we will parse "-60w" or "-60min", which we store in a time_t (whose signedness is technically implementation defined, but which is signed on all major compilers). However, when formatting these as ISO 8601 we get get garbed output like PT-1H-56M-9S, which we cannot parse and probably neither can anything else. (Taskwarrior, when asked to assign a negative duration to a duration-typed UDA, will store this garbled output but then reproduce it as PT0S, an unfortunate user experience.)

This PR updates Duration::formatISO to instead prepend a '-' before negative durations, and updates Duration::parse_designated to parse such things.

Alternative to #110, which simply blesses the garbled format by extending the parser to support it.

…in ISO format

According to [this MDN document](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration)
there is an ECMAScript extension to ISO 8601 to allow signed durations by putting
a + or - before the ISO duration format.

Internally we support signed durations -- we will parse "-60w" or "-60min",
which we store in a `time_t` (whose signedness is technically implementation
defined, but which is signed on all major compilers). However, when formatting
these as ISO 8601 we get get garbed output like PT-1H-56M-9S, which we cannot
parse and probably neither can anything else. (Taskwarrior, when asked to
assign a negative duration to a duration-typed UDA, will store this garbled
output but then reproduce it as PT0S, an unfortunate user experience.)

This PR updates `Duration::formatISO` to instead prepend a '-' before negative
durations, and updates `Duration::parse_designated` to parse such things.

Alternative to GothenburgBitFactory#110, which simply blesses the garbled format by extending the
parser to support it.
This will let us remove some special-case logic from Timewarrior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant