Commit 5df98cb
committed
Duration: support negative durations by prefixing a '-' before the P 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.1 parent 3da1534 commit 5df98cb
1 file changed
+16
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
220 | 223 | | |
221 | 224 | | |
222 | 225 | | |
223 | 226 | | |
224 | 227 | | |
225 | 228 | | |
226 | | - | |
| 229 | + | |
227 | 230 | | |
228 | 231 | | |
229 | 232 | | |
230 | 233 | | |
231 | 234 | | |
232 | | - | |
| 235 | + | |
233 | 236 | | |
234 | 237 | | |
235 | 238 | | |
236 | 239 | | |
237 | 240 | | |
238 | | - | |
| 241 | + | |
239 | 242 | | |
240 | 243 | | |
241 | 244 | | |
| |||
244 | 247 | | |
245 | 248 | | |
246 | 249 | | |
247 | | - | |
| 250 | + | |
248 | 251 | | |
249 | 252 | | |
250 | 253 | | |
251 | 254 | | |
252 | 255 | | |
253 | | - | |
| 256 | + | |
254 | 257 | | |
255 | 258 | | |
256 | 259 | | |
257 | 260 | | |
258 | 261 | | |
259 | | - | |
| 262 | + | |
260 | 263 | | |
261 | 264 | | |
262 | 265 | | |
| |||
454 | 457 | | |
455 | 458 | | |
456 | 459 | | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
457 | 467 | | |
458 | 468 | | |
459 | 469 | | |
460 | 470 | | |
461 | 471 | | |
462 | | - | |
463 | 472 | | |
464 | 473 | | |
465 | 474 | | |
| |||
0 commit comments