mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-27 20:58:16 +00:00
LibWeb/HTML: Correctly convert number to time/local datetime string
This fixes a bug where non-zero milliseconds were previously not included if the second component was zero.
This commit is contained in:
parent
354fd56046
commit
ec807d40dd
Notes:
github-actions[bot]
2025-08-14 15:06:42 +00:00
Author: https://github.com/skyz1
Commit: ec807d40dd
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5812
Reviewed-by: https://github.com/gmta
Reviewed-by: https://github.com/trflynn89
3 changed files with 10 additions and 14 deletions
|
@ -2422,11 +2422,10 @@ static Utf16String convert_number_to_time_string(double input)
|
|||
// string that represents the time that is input milliseconds after midnight on a day with no time changes.
|
||||
auto seconds = JS::sec_from_time(input);
|
||||
auto milliseconds = JS::ms_from_time(input);
|
||||
if (seconds > 0) {
|
||||
if (milliseconds > 0)
|
||||
return Utf16String::formatted("{:02d}:{:02d}:{:02d}.{:3d}", JS::hour_from_time(input), JS::min_from_time(input), seconds, milliseconds);
|
||||
return Utf16String::formatted("{:02d}:{:02d}:{:02d}.{:03d}", JS::hour_from_time(input), JS::min_from_time(input), seconds, milliseconds);
|
||||
if (seconds > 0)
|
||||
return Utf16String::formatted("{:02d}:{:02d}:{:02d}", JS::hour_from_time(input), JS::min_from_time(input), seconds);
|
||||
}
|
||||
return Utf16String::formatted("{:02d}:{:02d}", JS::hour_from_time(input), JS::min_from_time(input));
|
||||
}
|
||||
|
||||
|
@ -2444,12 +2443,10 @@ static Utf16String convert_number_to_local_date_and_time_string(double input)
|
|||
auto seconds = JS::sec_from_time(input);
|
||||
auto milliseconds = JS::ms_from_time(input);
|
||||
|
||||
if (seconds > 0) {
|
||||
if (milliseconds > 0)
|
||||
return Utf16String::formatted("{:04d}-{:02d}-{:02d}T{:02d}:{:02d}:{:02d}.{:03d}", year, month, day, hour, minutes, seconds, milliseconds);
|
||||
return Utf16String::formatted("{:04d}-{:02d}-{:02d}T{:02d}:{:02d}:{:02d}.{:03d}", year, month, day, hour, minutes, seconds, milliseconds).trim("0"sv, TrimMode::Right);
|
||||
if (seconds > 0)
|
||||
return Utf16String::formatted("{:04d}-{:02d}-{:02d}T{:02d}:{:02d}:{:02d}", year, month, day, hour, minutes, seconds);
|
||||
}
|
||||
|
||||
return Utf16String::formatted("{:04d}-{:02d}-{:02d}T{:02d}:{:02d}", year, month, day, hour, minutes);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,8 +34,8 @@ password threw exception: InvalidStateError: valueAsNumber: Invalid input type u
|
|||
date did not throw: 0
|
||||
month did not throw: 100
|
||||
week did not throw: 345600000
|
||||
time did not throw: 0
|
||||
datetime-local did not throw: 0
|
||||
time did not throw: 100
|
||||
datetime-local did not throw: 100
|
||||
color threw exception: InvalidStateError: valueAsNumber: Invalid input type used
|
||||
checkbox threw exception: InvalidStateError: valueAsNumber: Invalid input type used
|
||||
radio threw exception: InvalidStateError: valueAsNumber: Invalid input type used
|
||||
|
|
|
@ -2,8 +2,7 @@ Harness status: OK
|
|||
|
||||
Found 32 tests
|
||||
|
||||
31 Pass
|
||||
1 Fail
|
||||
32 Pass
|
||||
Pass time element of default time value
|
||||
Pass step attribute on default value check
|
||||
Pass max attribute on default value check
|
||||
|
@ -26,7 +25,7 @@ Pass stepUp on step value hour
|
|||
Pass stepDown on step value hour
|
||||
Pass stepUp on step value second
|
||||
Pass stepDown on step value second
|
||||
Fail stepUp on step value with fractional seconds
|
||||
Pass stepUp on step value with fractional seconds
|
||||
Pass stepDown on step value with fractional seconds
|
||||
Pass stepUp argument 2 times
|
||||
Pass stepDown argument 2 times
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue