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

[Temporal] Fix ZDT hoursInDay for non-integer hours

The hoursInDay could be fractional number on the date of changng
daylight saving time for time zone in half hours or some historical time
zone.
Ex: Australia/Lord_Howe on Sunday, April 3, 2022, 2:00:00 am clocks were
turned backward 0:30 hours to Sunday, April 3, 2022, 1:30:00 am local
standard time instead. so that day will have 24.5 hours.
On Sunday, October 2, 2022, 2:00:00 am clocks are turned forward 0:30
hours to Sunday, October 2, 2022, 2:30:00 am local daylight time
instead. So the hoursInDay for that day is only 23.5 hours.

Historically, Singapore from 1933 to 1941 moved clocks forward 20 minutes for daylight savings, resulting the day in 24.33333 and
23.66667 hours.

Test covered in https://github.com/tc39/test262/blob/main/test/staging/Temporal/ZonedDateTime/old/dst-properties.js

Change the return type from MaybeHandle<Smi> to MaybeHandle<Object> so
we can return non integer value. Also change the method of division by
first convert the value to second in BigInt, then divid 3600 (number of
seconds in a hour) in double.

Bug: v8:11544
Change-Id: Ia69d2606cd832e51f415a00440fb9cbc236883e4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3901619Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83311}
parent b16aa83f
......@@ -15763,7 +15763,7 @@ MaybeHandle<JSTemporalZonedDateTime> JSTemporalZonedDateTime::Constructor(
}
// #sec-get-temporal.zoneddatetime.prototype.hoursinday
MaybeHandle<Smi> JSTemporalZonedDateTime::HoursInDay(
MaybeHandle<Object> JSTemporalZonedDateTime::HoursInDay(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time) {
TEMPORAL_ENTER_FUNC();
const char* method_name = "Temporal.ZonedDateTime.prototype.hoursInDay";
......@@ -15837,15 +15837,23 @@ MaybeHandle<Smi> JSTemporalZonedDateTime::HoursInDay(
Smi);
// 15. Let diffNs be tomorrowInstant.[[Nanoseconds]] −
// todayInstant.[[Nanoseconds]].
// 16. Return 𝔽(diffNs / (3.6 × 10^12)).
int64_t diff_ns =
Handle<BigInt> diff_ns =
BigInt::Subtract(isolate,
handle(tomorrow_instant->nanoseconds(), isolate),
handle(today_instant->nanoseconds(), isolate))
.ToHandleChecked();
// 16. Return 𝔽(diffNs / (3.6 × 10^12)).
//
// Note: The result of the division may be non integer for TimeZone which
// change fractional hours. Perform this division in two steps:
// First convert it to seconds in BigInt, then perform floating point
// division (seconds / 3600) to convert to hours.
int64_t diff_seconds =
BigInt::Divide(isolate, diff_ns, BigInt::FromUint64(isolate, 1000000000))
.ToHandleChecked()
->AsInt64();
return handle(Smi::FromInt(static_cast<int32_t>(diff_ns / 3600000000000LL)),
isolate);
double hours_in_that_day = static_cast<double>(diff_seconds) / 3600.0;
return isolate->factory()->NewNumber(hours_in_that_day);
}
namespace {
......
......@@ -950,7 +950,7 @@ class JSTemporalZonedDateTime
Handle<Object> time_zone_like);
// #sec-get-temporal.zoneddatetime.prototype.hoursinday
V8_WARN_UNUSED_RESULT static MaybeHandle<Smi> HoursInDay(
V8_WARN_UNUSED_RESULT static MaybeHandle<Object> HoursInDay(
Isolate* isolate, Handle<JSTemporalZonedDateTime> zoned_date_time);
// #sec-temporal.zoneddatetime.prototype.round
......
......@@ -534,7 +534,6 @@
'staging/Temporal/Duration/old/total': [FAIL],
'staging/Temporal/ZonedDateTime/old/construction-and-properties': [FAIL],
'staging/Temporal/ZonedDateTime/old/dst-math': [FAIL],
'staging/Temporal/ZonedDateTime/old/dst-properties': [FAIL],
'staging/Temporal/ZonedDateTime/old/equals': [FAIL],
'staging/Temporal/ZonedDateTime/old/since': [FAIL],
'staging/Temporal/ZonedDateTime/old/toPlainMonthDay': [FAIL],
......@@ -940,6 +939,7 @@
'staging/Temporal/ZonedDateTime/old/add': [FAIL],
'staging/Temporal/ZonedDateTime/old/compare': [FAIL],
'staging/Temporal/ZonedDateTime/old/date-time-hours-overflow': [FAIL],
'staging/Temporal/ZonedDateTime/old/dst-properties': [FAIL],
'staging/Temporal/ZonedDateTime/old/order-of-operations': [FAIL],
'staging/Temporal/ZonedDateTime/old/property-bags': [FAIL],
'staging/Temporal/ZonedDateTime/old/reversibility-of-differences': [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