Commit adb111b7 authored by Frank Tang's avatar Frank Tang Committed by V8 LUCI CQ

[Temporal] Fix PlainTime/PlainDateTime toString bugs

Bug: v8:11544
Change-Id: Iaf3d673c9746badadae082121402e723d3704189
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3719087Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81506}
parent 7de527df
......@@ -1476,31 +1476,39 @@ void FormatSecondsStringPart(IncrementalStringBuilder* builder, int32_t second,
builder->AppendCharacter(':');
ToZeroPaddedDecimalString(builder, second, 2);
// 4. Let fraction be millisecond × 10^6 + microsecond × 10^3 + nanosecond.
int32_t fraction = millisecond * 1000000 + microsecond * 1000 + nanosecond;
// 5. If fraction is 0, return secondsString.
if (fraction == 0) return;
// 6. Set fraction to fraction formatted as a nine-digit decimal number,
// padded to the left with zeroes if necessary.
builder->AppendCharacter('.');
// 7. If precision is "auto", then
int32_t divisor = 100000000;
int64_t fraction = millisecond * 1000000 + microsecond * 1000 + nanosecond;
int64_t divisor = 100000000;
// 5. If precision is "auto", then
if (precision == Precision::kAuto) {
// a. Set fraction to the
// longest possible substring of fraction starting at position 0 and not
// ending with the code unit 0x0030 (DIGIT ZERO).
do {
builder->AppendInt(fraction / divisor);
// a. If fraction is 0, return secondsString.
if (fraction == 0) {
return;
}
builder->AppendCharacter('.');
// b. Set fraction to ToZeroPaddedDecimalString(fraction, 9).
// c. Set fraction to the longest possible substring of fraction starting at
// position 0 and not ending with the code unit 0x0030 (DIGIT ZERO).
while (fraction > 0) {
builder->AppendInt(static_cast<int32_t>(fraction / divisor));
fraction %= divisor;
divisor /= 10;
} while (fraction > 0);
}
// 6. Else,
} else {
// a. If precision is 0, return secondsString.
if (precision == Precision::k0) {
return;
}
builder->AppendCharacter('.');
// b. Set fraction to ToZeroPaddedDecimalString(fraction, 9).
// c. Set fraction to the substring of fraction from 0 to precision.
int32_t precision_len = static_cast<int32_t>(precision);
DCHECK_LE(0, precision_len);
DCHECK_GE(9, precision_len);
for (int32_t len = 0; len < precision_len;
len++, fraction %= divisor, divisor /= 10) {
builder->AppendInt(fraction / divisor);
for (int32_t len = 0; len < precision_len; len++) {
builder->AppendInt(static_cast<int32_t>(fraction / divisor));
fraction %= divisor;
divisor /= 10;
}
}
// 7. Return the string-concatenation of secondsString, the code unit 0x002E
......@@ -1516,7 +1524,7 @@ Handle<String> TemporalTimeToString(Isolate* isolate,
IncrementalStringBuilder builder(isolate);
// 2. Let hour be ToZeroPaddedDecimalString(hour, 2).
ToZeroPaddedDecimalString(&builder, time.hour, 2);
builder.AppendCharacter('-');
builder.AppendCharacter(':');
// 3. Let minute be ToZeroPaddedDecimalString(minute, 2).
ToZeroPaddedDecimalString(&builder, time.minute, 2);
// 4. Let seconds be ! FormatSecondsStringPart(second, millisecond,
......
......@@ -522,7 +522,6 @@
'built-ins/Temporal/Instant/prototype/round/subclassing-ignored': [FAIL],
'built-ins/Temporal/Instant/prototype/since/argument-zoneddatetime': [FAIL],
'built-ins/Temporal/Instant/prototype/since/largestunit': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/smallestunit-valid-units': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/timezone': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/timezone-offset': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/timezone-string-datetime': [FAIL],
......@@ -678,7 +677,6 @@
'built-ins/Temporal/PlainDateTime/prototype/since/smallestunit-wrong-type': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/subtract/balance-negative-time-units': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/toPlainDate/limits': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/toString/smallestunit-valid-units': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/balance-negative-time-units': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/disambiguation-undefined': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/options-undefined': [FAIL],
......@@ -766,15 +764,6 @@
'built-ins/Temporal/PlainTime/prototype/since/smallestunit-undefined': [FAIL],
'built-ins/Temporal/PlainTime/prototype/since/smallestunit-wrong-type': [FAIL],
'built-ins/Temporal/PlainTime/prototype/subtract/balance-negative-time-units': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-non-integer': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-undefined': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-wrong-type': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/options-undefined': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/roundingmode-undefined': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/roundingmode-wrong-type': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/smallestunit-undefined': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/smallestunit-valid-units': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/smallestunit-wrong-type': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toZonedDateTime/timezone-getpossibleinstantsfor-iterable': [SKIP],
'built-ins/Temporal/PlainTime/prototype/toZonedDateTime/timezone-string-multiple-offsets': [FAIL],
'built-ins/Temporal/PlainTime/prototype/until/argument-string-with-utc-designator': [FAIL],
......@@ -1213,15 +1202,6 @@
'built-ins/Temporal/PlainTime/prototype/since/year-zero': [FAIL],
'built-ins/Temporal/PlainTime/prototype/subtract/argument-object': [FAIL],
'built-ins/Temporal/PlainTime/prototype/subtract/argument-string-fractional-units-rounding-mode': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/basic': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-auto': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-number': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/rounding-cross-midnight': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/roundingmode-ceil': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/roundingmode-floor': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/roundingmode-halfExpand': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/roundingmode-trunc': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toString/smallestunit-fractionalseconddigits': [FAIL],
'built-ins/Temporal/PlainTime/prototype/until/argument-cast': [FAIL],
'built-ins/Temporal/PlainTime/prototype/until/argument-string-no-implicit-midnight': [FAIL],
'built-ins/Temporal/PlainTime/prototype/until/argument-string-time-designator-required-for-disambiguation': [FAIL],
......@@ -1305,8 +1285,6 @@
'built-ins/Temporal/Duration/prototype/round/roundto-invalid-string': [FAIL],
'built-ins/Temporal/Duration/prototype/subtract/options-wrong-type': [FAIL],
'built-ins/Temporal/Instant/prototype/round/rounding-direction': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/fractionalseconddigits-number': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/rounding-cross-midnight': [FAIL],
'built-ins/Temporal/Instant/prototype/toString/rounding-direction': [FAIL],
'built-ins/Temporal/PlainDate/prototype/since/options-wrong-type': [FAIL],
'built-ins/Temporal/PlainDate/prototype/until/options-wrong-type': [FAIL],
......@@ -1347,8 +1325,6 @@
'built-ins/Temporal/PlainDateTime/prototype/since/round-relative-to-receiver': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/since/subseconds': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/since/weeks-months-mutually-exclusive': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/toString/fractionalseconddigits-number': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/toString/rounding-cross-midnight': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/until/argument-object': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/until/argument-string': [FAIL],
'built-ins/Temporal/PlainDateTime/prototype/until/options-empty': [FAIL],
......@@ -1591,7 +1567,6 @@
'built-ins/Temporal/PlainTime/prototype/since/argument-string-time-separators': [FAIL],
'built-ins/Temporal/PlainTime/prototype/since/leap-second': [FAIL],
'built-ins/Temporal/PlainTime/prototype/subtract/argument-string-negative-fractional-units': [FAIL],
'built-ins/Temporal/PlainTime/prototype/toJSON/basic': [FAIL],
'built-ins/Temporal/PlainTime/prototype/until/argument-string-time-separators': [FAIL],
'built-ins/Temporal/PlainTime/prototype/until/leap-second': [FAIL],
'built-ins/Temporal/PlainYearMonth/prototype/since/argument-propertybag-calendar-leap-second': [FAIL],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment