Skip to content

Commit 49b5f71

Browse files
committed
Add tests for parsing fractional durations between -1 and +1 seconds
Extend tests for existing fractional durations parsing behaviour. Parsing "PT0,6S" should result in a positive microsecond, which will be fixed in the next commit. The parser currently accepts both a negative prefix "-PT" and a negative value in the components "-0,6S". Combining both into "-PT-0,6S" is also accepted by the parser, resulting in an overall positive duration. Although the practical value of double negative durations is dubious, the accepting nature of the parser is tested. The JavaScript libraries that I tested disagree whether "-PT-0,6S" represents a positive or negative duration, "moment" and "tinyduration" reported positive, "luxon" (the successor to moment) reported negative. If the parser accepts double negatives at all, resulting in anything but a positive duration would be unintuitive.
1 parent 6701f22 commit 49b5f71

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

lib/elixir/test/elixir/calendar/duration_test.exs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ defmodule DurationTest do
264264
assert Duration.from_iso8601!("PT6S") == %Duration{second: 6}
265265
assert Duration.from_iso8601!("PT1,6S") == %Duration{second: 1, microsecond: {600_000, 1}}
266266
assert Duration.from_iso8601!("PT-1.6S") == %Duration{second: -1, microsecond: {-600_000, 1}}
267+
assert _faulty = Duration.from_iso8601!("PT0,6S") == %Duration{second: 0, microsecond: {-600_000, 1}}
268+
assert Duration.from_iso8601!("PT-0,6S") == %Duration{second: 0, microsecond: {-600_000, 1}}
269+
assert Duration.from_iso8601!("-PT-0,6S") == %Duration{second: 0, microsecond: {600_000, 1}}
267270
assert Duration.from_iso8601!("-P10DT4H") == %Duration{day: -10, hour: -4}
268271
assert Duration.from_iso8601!("-P10DT-4H") == %Duration{day: -10, hour: 4}
269272
assert Duration.from_iso8601!("P-10D") == %Duration{day: -10}

0 commit comments

Comments
 (0)