mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:37:35 +00:00
LibJS: Fix nanoseconds formatting in format_time_zone_offset_string()
Two issues: - The format string said "{:9}", which left-pads with spaces and not zeros as required - Even when correcting that, we were not accounting for step 11 b: "Set fraction to the longest possible substring of fraction starting at position 0 and not ending with the code unit 0x0030 (DIGIT ZERO)." We can safely use trim() for that as the formatted string is known to not contain only zeros (which would leave the left-most in place). Also adds tests for "UTC" and various numeric offsets.
This commit is contained in:
parent
68d80d239b
commit
e93ce1ff69
2 changed files with 15 additions and 3 deletions
|
@ -336,7 +336,7 @@ String format_time_zone_offset_string(double offset_nanoseconds)
|
|||
// a. Let fraction be nanoseconds, formatted as a nine-digit decimal number, padded to the left with zeroes if necessary.
|
||||
// b. Set fraction to the longest possible substring of fraction starting at position 0 and not ending with the code unit 0x0030 (DIGIT ZERO).
|
||||
// c. Let post be the string-concatenation of the code unit 0x003A (COLON), s, the code unit 0x002E (FULL STOP), and fraction.
|
||||
builder.appendff(":{:02}.{:9}", seconds, nanoseconds);
|
||||
builder.appendff(":{:02}.{}", seconds, String::formatted("{:09}", nanoseconds).trim("0"sv, TrimMode::Right));
|
||||
}
|
||||
// 12. Else if seconds ≠ 0, then
|
||||
else if (seconds != 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue