LibJS: Implement the ECMA-402 definition of DefaultTimeZone

Simply defer to LibTimeZone to retrieve the system's current time zone.
Also update some Temporal tests to explicitly set the time zone to UTC.
This commit is contained in:
Timothy Flynn 2022-01-11 23:23:41 -05:00 committed by Linus Groh
parent bdf02c21e1
commit f6786881aa
6 changed files with 10 additions and 10 deletions

View file

@ -56,11 +56,11 @@ String canonicalize_time_zone_name(String const& time_zone)
}
// 11.1.3 DefaultTimeZone ( ), https://tc39.es/proposal-temporal/#sec-defaulttimezone
// NOTE: This is the minimum implementation of DefaultTimeZone, supporting only the "UTC" time zone.
// 15.1.3 DefaultTimeZone ( ), https://tc39.es/proposal-temporal/#sup-defaulttimezone
String default_time_zone()
{
// 1. Return "UTC".
return "UTC";
// The DefaultTimeZone abstract operation returns a String value representing the valid (11.1.1) and canonicalized (11.1.2) time zone name for the host environment's current time zone.
return ::TimeZone::current_time_zone();
}
// 11.6.1 ParseTemporalTimeZone ( string ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaltimezone

View file

@ -17,7 +17,7 @@ describe("correct behavior", () => {
return 86400000000000;
},
};
const plainDate = Temporal.Now.plainDate(calendar);
const plainDate = Temporal.Now.plainDate(calendar, "UTC");
const plainDateWithOffset = Temporal.Now.plainDate(calendar, timeZone);
if (plainDate.dayOfYear === plainDate.daysInYear) {
expect(plainDateWithOffset.year).toBe(plainDate.year + 1);

View file

@ -15,7 +15,7 @@ describe("correct behavior", () => {
return 86400000000000;
},
};
const plainDate = Temporal.Now.plainDateISO();
const plainDate = Temporal.Now.plainDateISO("UTC");
const plainDateWithOffset = Temporal.Now.plainDateISO(timeZone);
if (plainDate.dayOfYear === plainDate.daysInYear) {
expect(plainDateWithOffset.year).toBe(plainDate.year + 1);

View file

@ -37,7 +37,7 @@ describe("correct behavior", () => {
},
};
const plainDateTime = Temporal.Now.plainDateTime(calendar);
const plainDateTime = Temporal.Now.plainDateTime(calendar, "UTC");
const plainDateTimeWithOffset = Temporal.Now.plainDateTime(calendar, timeZone);
if (plainDateTime.year !== plainDateTimeWithOffset.year) return;
@ -58,7 +58,7 @@ describe("correct behavior", () => {
},
};
const plainDateTime = Temporal.Now.plainDateTime(calendar);
const plainDateTime = Temporal.Now.plainDateTime(calendar, "UTC");
const plainDateTimeWithOffset = Temporal.Now.plainDateTime(calendar, timeZone);
if (plainDateTime.year !== plainDateTimeWithOffset.year) return;

View file

@ -35,7 +35,7 @@ describe("correct behavior", () => {
},
};
const plainDateTime = Temporal.Now.plainDateTimeISO();
const plainDateTime = Temporal.Now.plainDateTimeISO("UTC");
const plainDateTimeWithOffset = Temporal.Now.plainDateTimeISO(timeZone);
if (plainDateTime.year !== plainDateTimeWithOffset.year) return;
@ -55,7 +55,7 @@ describe("correct behavior", () => {
},
};
const plainDateTime = Temporal.Now.plainDateTimeISO();
const plainDateTime = Temporal.Now.plainDateTimeISO("UTC");
const plainDateTimeWithOffset = Temporal.Now.plainDateTimeISO(timeZone);
if (plainDateTime.year !== plainDateTimeWithOffset.year) return;

View file

@ -15,7 +15,7 @@ describe("correct behavior", () => {
return 86400000000000;
},
};
const plainTime = Temporal.Now.plainTimeISO();
const plainTime = Temporal.Now.plainTimeISO("UTC");
const plainTimeWithOffset = Temporal.Now.plainTimeISO(timeZone);
// FIXME: Compare these in a sensible way
});