Duration: support negative durations by prefixing a '-' before the P in ISO format #111
+44
−16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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::formatISOto instead prepend a '-' before negative durations, and updatesDuration::parse_designatedto parse such things.Alternative to #110, which simply blesses the garbled format by extending the parser to support it.