瀏覽代碼

LibJS: Fix fractionalSecondDigits behavior in Duration.proto.toString()

This is a normative change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/3ee771e
Linus Groh 3 年之前
父節點
當前提交
acce65b52c
共有 1 個文件被更改,包括 2 次插入2 次删除
  1. 2 2
      Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp

+ 2 - 2
Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp

@@ -1778,8 +1778,8 @@ String temporal_duration_to_string(double years, double months, double weeks, do
         time_part.append('M');
     }
 
-    // 21. If any of seconds, milliseconds, microseconds, and nanoseconds are not 0; or years, months, weeks, days, hours, and minutes are all 0, then
-    if ((seconds != 0 || milliseconds != 0 || microseconds != 0 || nanoseconds != 0) || (years == 0 && months == 0 && weeks == 0 && days == 0 && hours == 0 && minutes == 0)) {
+    // 21. If any of seconds, milliseconds, microseconds, and nanoseconds are not 0; or years, months, weeks, days, hours, and minutes are all 0; or precision is not "auto"; then
+    if ((seconds != 0 || milliseconds != 0 || microseconds != 0 || nanoseconds != 0) || (years == 0 && months == 0 && weeks == 0 && days == 0 && hours == 0 && minutes == 0) || (precision.has<StringView>() && precision.get<StringView>() != "auto"sv)) {
         // a. Let fraction be abs(milliseconds) × 10^6 + abs(microseconds) × 10^3 + abs(nanoseconds).
         auto fraction = fabs(milliseconds) * 1'000'000 + fabs(microseconds) * 1'000 + fabs(nanoseconds);