Skip to content

Commit a6fca52

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 ad3646e commit a6fca52

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
@@ -262,6 +262,9 @@ defmodule DurationTest do
262262
assert Duration.from_iso8601!("PT6S") == %Duration{second: 6}
263263
assert Duration.from_iso8601!("PT1,6S") == %Duration{second: 1, microsecond: {600_000, 1}}
264264
assert Duration.from_iso8601!("PT-1.6S") == %Duration{second: -1, microsecond: {-600_000, 1}}
265+
assert _faulty = Duration.from_iso8601!("PT0,6S") == %Duration{second: 0, microsecond: {-600_000, 1}}
266+
assert Duration.from_iso8601!("PT-0,6S") == %Duration{second: 0, microsecond: {-600_000, 1}}
267+
assert Duration.from_iso8601!("-PT-0,6S") == %Duration{second: 0, microsecond: {600_000, 1}}
265268
assert Duration.from_iso8601!("-P10DT4H") == %Duration{day: -10, hour: -4}
266269
assert Duration.from_iso8601!("-P10DT-4H") == %Duration{day: -10, hour: 4}
267270
assert Duration.from_iso8601!("P-10D") == %Duration{day: -10}

0 commit comments

Comments
 (0)