Skip to content
Permalink
Browse files
Temporal.Duration#toString should never ignore fractionalSecondDigits
https://bugs.webkit.org/show_bug.cgi?id=240193

Reviewed by Yusuke Suzuki.

This patch implements the spec correction of tc39/proposal-temporal#1956:
`new Temporal.Duration.from(1).toString({ fractionalSecondDigits: 2 })` should be P1Y0.00S, not just P1Y.

* stress/temporal-duration.js: Add a test case.
* test262/expectations.yaml: Mark two test cases as passing.

* runtime/TemporalDuration.cpp:
(JSC::TemporalDuration::toString):

Canonical link: https://commits.webkit.org/250388@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@293942 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
rkirsling committed May 7, 2022
1 parent 101730a commit 399478b08c4dcf56de6a283b1a5e0f30e13bbe1f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
@@ -1,3 +1,13 @@
2022-05-06 Ross Kirsling <ross.kirsling@sony.com>

Temporal.Duration#toString should never ignore fractionalSecondDigits
https://bugs.webkit.org/show_bug.cgi?id=240193

Reviewed by Yusuke Suzuki.

* stress/temporal-duration.js: Add a test case.
* test262/expectations.yaml: Mark two test cases as passing.

2022-05-06 Ross Kirsling <ross.kirsling@sony.com>

ISO8601::Duration should guard against -0
@@ -281,6 +281,7 @@ for (let i = 1; i < 10; i++)
shouldBe(pos.toString({ fractionalSecondDigits: i }), `P1Y2M3W4DT5H6M7.${decimalPart.slice(0,i)}S`);
shouldBe(pos.toString({ fractionalSecondDigits: 'auto' }), pos.toString());
shouldBe(zero.toString({ fractionalSecondDigits: 2 }), 'PT0.00S');
shouldBe(new Temporal.Duration(1).toString({ fractionalSecondDigits: 2 }), 'P1YT0.00S');

shouldThrow(() => pos.toString({ roundingMode: 'bogus' }), RangeError);
shouldBe(pos.toString({ roundingMode: 'trunc' }), pos.toString());
@@ -1020,9 +1020,6 @@ test/built-ins/Temporal/Duration/prototype/subtract/timezone-string-leap-second.
test/built-ins/Temporal/Duration/prototype/subtract/timezone-wrong-type.js:
default: 'Test262Error: symbol is not a valid object and does not convert to a string Expected a TypeError but got a RangeError'
strict mode: 'Test262Error: symbol is not a valid object and does not convert to a string Expected a TypeError but got a RangeError'
test/built-ins/Temporal/Duration/prototype/toString/fractionalseconddigits-exact-number-of-digits.js:
default: 'Test262Error: Expected SameValue(«P3Y», «P3YT0S») to be true'
strict mode: 'Test262Error: Expected SameValue(«P3Y», «P3YT0S») to be true'
test/built-ins/Temporal/Duration/prototype/total/calendar-dateadd-called-with-options-undefined.js:
default: "TypeError: undefined is not a constructor (evaluating 'new Temporal.ZonedDateTime(0n, timeZone, calendar)')"
strict mode: "TypeError: undefined is not a constructor (evaluating 'new Temporal.ZonedDateTime(0n, timeZone, calendar)')"
@@ -1,3 +1,16 @@
2022-05-06 Ross Kirsling <ross.kirsling@sony.com>

Temporal.Duration#toString should never ignore fractionalSecondDigits
https://bugs.webkit.org/show_bug.cgi?id=240193

Reviewed by Yusuke Suzuki.

This patch implements the spec correction of https://github.com/tc39/proposal-temporal/pull/1956:
`new Temporal.Duration(1).toString({ fractionalSecondDigits: 2 })` should be P1Y0.00S, not just P1Y.

* runtime/TemporalDuration.cpp:
(JSC::TemporalDuration::toString):

2022-05-06 Ross Kirsling <ross.kirsling@sony.com>

ISO8601::Duration should guard against -0
@@ -605,7 +605,7 @@ String TemporalDuration::toString(const ISO8601::Duration& duration, std::tuple<
builder.append(formatInteger(duration.days()), 'D');

// The zero value is displayed in seconds.
auto usesSeconds = balancedSeconds || balancedMilliseconds || balancedMicroseconds || balancedNanoseconds || !sign;
auto usesSeconds = balancedSeconds || balancedMilliseconds || balancedMicroseconds || balancedNanoseconds || !sign || std::get<0>(precision) != Precision::Auto;
if (!duration.hours() && !duration.minutes() && !usesSeconds)
return builder.toString();

0 comments on commit 399478b

Please sign in to comment.