Title: [293942] trunk
Revision
293942
Author
ross.kirsl...@sony.com
Date
2022-05-06 18:52:24 -0700 (Fri, 06 May 2022)

Log Message

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.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

Modified Paths

Diff

Modified: trunk/JSTests/ChangeLog (293941 => 293942)


--- trunk/JSTests/ChangeLog	2022-05-07 01:41:06 UTC (rev 293941)
+++ trunk/JSTests/ChangeLog	2022-05-07 01:52:24 UTC (rev 293942)
@@ -1,5 +1,15 @@
 2022-05-06  Ross Kirsling  <ross.kirsl...@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.kirsl...@sony.com>
+
         ISO8601::Duration should guard against -0
         https://bugs.webkit.org/show_bug.cgi?id=240185
 

Modified: trunk/JSTests/stress/temporal-duration.js (293941 => 293942)


--- trunk/JSTests/stress/temporal-duration.js	2022-05-07 01:41:06 UTC (rev 293941)
+++ trunk/JSTests/stress/temporal-duration.js	2022-05-07 01:52:24 UTC (rev 293942)
@@ -281,6 +281,7 @@
     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());

Modified: trunk/JSTests/test262/expectations.yaml (293941 => 293942)


--- trunk/JSTests/test262/expectations.yaml	2022-05-07 01:41:06 UTC (rev 293941)
+++ trunk/JSTests/test262/expectations.yaml	2022-05-07 01:52:24 UTC (rev 293942)
@@ -1020,9 +1020,6 @@
 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)')"

Modified: trunk/Source/_javascript_Core/ChangeLog (293941 => 293942)


--- trunk/Source/_javascript_Core/ChangeLog	2022-05-07 01:41:06 UTC (rev 293941)
+++ trunk/Source/_javascript_Core/ChangeLog	2022-05-07 01:52:24 UTC (rev 293942)
@@ -1,5 +1,18 @@
 2022-05-06  Ross Kirsling  <ross.kirsl...@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.kirsl...@sony.com>
+
         ISO8601::Duration should guard against -0
         https://bugs.webkit.org/show_bug.cgi?id=240185
 

Modified: trunk/Source/_javascript_Core/runtime/TemporalDuration.cpp (293941 => 293942)


--- trunk/Source/_javascript_Core/runtime/TemporalDuration.cpp	2022-05-07 01:41:06 UTC (rev 293941)
+++ trunk/Source/_javascript_Core/runtime/TemporalDuration.cpp	2022-05-07 01:52:24 UTC (rev 293942)
@@ -605,7 +605,7 @@
         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();
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to