Skip to content

Commit

Permalink
Replace Temporal.ZonedDateTime.timeZone getter with new API
Browse files Browse the repository at this point in the history
This is the replacement of the old API with the new API, .timeZoneId and
.getTimeZone(). Semantics will be corrected in the following commit.

Normative PR: tc39/proposal-temporal#2482
  • Loading branch information
ptomato committed Feb 17, 2023
1 parent 1251e06 commit 6c71cf6
Show file tree
Hide file tree
Showing 90 changed files with 416 additions and 274 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ description: Time zone names are case insensitive
features: [Temporal]
---*/

const instance = new Temporal.Instant(0n);
const instance = new Temporal.Instant(0n);

const timeZone = 'uTc';
const result = instance.toZonedDateTime({ timeZone, calendar: "iso8601" });
assert.sameValue(result.timeZone.id, 'UTC', `Time zone created from string "${timeZone}"`);
assert.sameValue(result.timeZoneId, 'UTC', `Time zone created from string "${timeZone}"`);
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@ assert.throws(RangeError, () => instance.toZonedDateTime({ timeZone: { timeZone

timeZone = "2021-08-19T17:30Z";
const result1 = instance.toZonedDateTime({ timeZone, calendar: "iso8601" });
assert.sameValue(result1.timeZone.id, "UTC", "date-time + Z is UTC time zone");
assert.sameValue(result1.timeZoneId, "UTC", "date-time + Z is UTC time zone");
const result2 = instance.toZonedDateTime({ timeZone: { timeZone }, calendar: "iso8601" });
assert.sameValue(result2.timeZone.id, "UTC", "date-time + Z is UTC time zone (string in property bag)");
assert.sameValue(result2.timeZoneId, "UTC", "date-time + Z is UTC time zone (string in property bag)");

timeZone = "2021-08-19T17:30-07:00";
const result3 = instance.toZonedDateTime({ timeZone, calendar: "iso8601" });
assert.sameValue(result3.timeZone.id, "-07:00", "date-time + offset is the offset time zone");
assert.sameValue(result3.timeZoneId, "-07:00", "date-time + offset is the offset time zone");
const result4 = instance.toZonedDateTime({ timeZone: { timeZone }, calendar: "iso8601" });
assert.sameValue(result4.timeZone.id, "-07:00", "date-time + offset is the offset time zone (string in property bag)");
assert.sameValue(result4.timeZoneId, "-07:00", "date-time + offset is the offset time zone (string in property bag)");

timeZone = "2021-08-19T17:30[UTC]";
const result5 = instance.toZonedDateTime({ timeZone, calendar: "iso8601" });
assert.sameValue(result5.timeZone.id, "UTC", "date-time + IANA annotation is the IANA time zone");
assert.sameValue(result5.timeZoneId, "UTC", "date-time + IANA annotation is the IANA time zone");
const result6 = instance.toZonedDateTime({ timeZone: { timeZone }, calendar: "iso8601" });
assert.sameValue(result6.timeZone.id, "UTC", "date-time + IANA annotation is the IANA time zone (string in property bag)");
assert.sameValue(result6.timeZoneId, "UTC", "date-time + IANA annotation is the IANA time zone (string in property bag)");

timeZone = "2021-08-19T17:30Z[UTC]";
const result7 = instance.toZonedDateTime({ timeZone, calendar: "iso8601" });
assert.sameValue(result7.timeZone.id, "UTC", "date-time + Z + IANA annotation is the IANA time zone");
assert.sameValue(result7.timeZoneId, "UTC", "date-time + Z + IANA annotation is the IANA time zone");
const result8 = instance.toZonedDateTime({ timeZone: { timeZone }, calendar: "iso8601" });
assert.sameValue(result8.timeZone.id, "UTC", "date-time + Z + IANA annotation is the IANA time zone (string in property bag)");
assert.sameValue(result8.timeZoneId, "UTC", "date-time + Z + IANA annotation is the IANA time zone (string in property bag)");

timeZone = "2021-08-19T17:30-07:00[UTC]";
const result9 = instance.toZonedDateTime({ timeZone, calendar: "iso8601" });
assert.sameValue(result9.timeZone.id, "UTC", "date-time + offset + IANA annotation is the IANA time zone");
assert.sameValue(result9.timeZoneId, "UTC", "date-time + offset + IANA annotation is the IANA time zone");
const result10 = instance.toZonedDateTime({ timeZone: { timeZone }, calendar: "iso8601" });
assert.sameValue(result10.timeZone.id, "UTC", "date-time + offset + IANA annotation is the IANA time zone (string in property bag)");
assert.sameValue(result10.timeZoneId, "UTC", "date-time + offset + IANA annotation is the IANA time zone (string in property bag)");
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const instance = new Temporal.Instant(0n);
let timeZone = "2016-12-31T23:59:60+00:00[UTC]";

const result1 = instance.toZonedDateTime({ timeZone, calendar: "iso8601" });
assert.sameValue(result1.timeZone.id, "UTC", "leap second is a valid ISO string for TimeZone");
assert.sameValue(result1.timeZoneId, "UTC", "leap second is a valid ISO string for TimeZone");
const result2 = instance.toZonedDateTime({ timeZone: { timeZone }, calendar: "iso8601" });
assert.sameValue(result2.timeZone.id, "UTC", "leap second is a valid ISO string for TimeZone (nested property)");
assert.sameValue(result2.timeZoneId, "UTC", "leap second is a valid ISO string for TimeZone (nested property)");

timeZone = "2021-08-19T17:30:45.123456789+23:59[+23:59:60]";
assert.throws(RangeError, () => instance.toZonedDateTime({ timeZone, calendar: "iso8601" }), "leap second in time zone name not valid");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ const instance = new Temporal.Instant(0n);
const timeZone = "2021-08-19T17:30:45.123456789+01:46[+01:45:30.987654321]";

const result1 = instance.toZonedDateTime({ timeZone, calendar: "iso8601" });
assert.sameValue(result1.timeZone.id, "+01:45:30.987654321", "Time zone string determined from bracket name");
assert.sameValue(result1.timeZoneId, "+01:45:30.987654321", "Time zone string determined from bracket name");
const result2 = instance.toZonedDateTime({ timeZone: { timeZone }, calendar: "iso8601" });
assert.sameValue(result2.timeZone.id, "+01:45:30.987654321", "Time zone string determined from bracket name");
assert.sameValue(result2.timeZoneId, "+01:45:30.987654321", "Time zone string determined from bracket name");
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ const instance = new Temporal.Instant(0n);

["UTC", "+01:30"].forEach((timeZone) => {
const result = instance.toZonedDateTime({ timeZone, calendar: "iso8601" });
assert.sameValue(result.timeZone.id, timeZone, `Time zone created from string "${timeZone}"`);
assert.sameValue(result.getISOFields().timeZone, timeZone, `time zone slot should store string "${timeZone}"`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ description: Time zone names are case insensitive
features: [Temporal]
---*/

const instance = new Temporal.Instant(0n);
const instance = new Temporal.Instant(0n);

const timeZone = 'uTc';
const result = instance.toZonedDateTimeISO(timeZone);
assert.sameValue(result.timeZone.id, 'UTC', `Time zone created from string "${timeZone}"`);
assert.sameValue(result.timeZoneId, 'UTC', `Time zone created from string "${timeZone}"`);
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@ assert.throws(RangeError, () => instance.toZonedDateTimeISO({ timeZone }), "bare

timeZone = "2021-08-19T17:30Z";
const result1 = instance.toZonedDateTimeISO(timeZone);
assert.sameValue(result1.timeZone.id, "UTC", "date-time + Z is UTC time zone");
assert.sameValue(result1.timeZoneId, "UTC", "date-time + Z is UTC time zone");
const result2 = instance.toZonedDateTimeISO({ timeZone });
assert.sameValue(result2.timeZone.id, "UTC", "date-time + Z is UTC time zone (string in property bag)");
assert.sameValue(result2.timeZoneId, "UTC", "date-time + Z is UTC time zone (string in property bag)");

timeZone = "2021-08-19T17:30-07:00";
const result3 = instance.toZonedDateTimeISO(timeZone);
assert.sameValue(result3.timeZone.id, "-07:00", "date-time + offset is the offset time zone");
assert.sameValue(result3.timeZoneId, "-07:00", "date-time + offset is the offset time zone");
const result4 = instance.toZonedDateTimeISO({ timeZone });
assert.sameValue(result4.timeZone.id, "-07:00", "date-time + offset is the offset time zone (string in property bag)");
assert.sameValue(result4.timeZoneId, "-07:00", "date-time + offset is the offset time zone (string in property bag)");

timeZone = "2021-08-19T17:30[UTC]";
const result5 = instance.toZonedDateTimeISO(timeZone);
assert.sameValue(result5.timeZone.id, "UTC", "date-time + IANA annotation is the IANA time zone");
assert.sameValue(result5.timeZoneId, "UTC", "date-time + IANA annotation is the IANA time zone");
const result6 = instance.toZonedDateTimeISO({ timeZone });
assert.sameValue(result6.timeZone.id, "UTC", "date-time + IANA annotation is the IANA time zone (string in property bag)");
assert.sameValue(result6.timeZoneId, "UTC", "date-time + IANA annotation is the IANA time zone (string in property bag)");

timeZone = "2021-08-19T17:30Z[UTC]";
const result7 = instance.toZonedDateTimeISO(timeZone);
assert.sameValue(result7.timeZone.id, "UTC", "date-time + Z + IANA annotation is the IANA time zone");
assert.sameValue(result7.timeZoneId, "UTC", "date-time + Z + IANA annotation is the IANA time zone");
const result8 = instance.toZonedDateTimeISO({ timeZone });
assert.sameValue(result8.timeZone.id, "UTC", "date-time + Z + IANA annotation is the IANA time zone (string in property bag)");
assert.sameValue(result8.timeZoneId, "UTC", "date-time + Z + IANA annotation is the IANA time zone (string in property bag)");

timeZone = "2021-08-19T17:30-07:00[UTC]";
const result9 = instance.toZonedDateTimeISO(timeZone);
assert.sameValue(result9.timeZone.id, "UTC", "date-time + offset + IANA annotation is the IANA time zone");
assert.sameValue(result9.timeZoneId, "UTC", "date-time + offset + IANA annotation is the IANA time zone");
const result10 = instance.toZonedDateTimeISO({ timeZone });
assert.sameValue(result10.timeZone.id, "UTC", "date-time + offset + IANA annotation is the IANA time zone (string in property bag)");
assert.sameValue(result10.timeZoneId, "UTC", "date-time + offset + IANA annotation is the IANA time zone (string in property bag)");
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const instance = new Temporal.Instant(0n);
let timeZone = "2016-12-31T23:59:60+00:00[UTC]";

const result1 = instance.toZonedDateTimeISO(timeZone);
assert.sameValue(result1.timeZone.id, "UTC", "leap second is a valid ISO string for TimeZone");
assert.sameValue(result1.timeZoneId, "UTC", "leap second is a valid ISO string for TimeZone");
const result2 = instance.toZonedDateTimeISO({ timeZone });
assert.sameValue(result2.timeZone.id, "UTC", "leap second is a valid ISO string for TimeZone (nested property)");
assert.sameValue(result2.timeZoneId, "UTC", "leap second is a valid ISO string for TimeZone (nested property)");

timeZone = "2021-08-19T17:30:45.123456789+23:59[+23:59:60]";
assert.throws(RangeError, () => instance.toZonedDateTimeISO(timeZone), "leap second in time zone name not valid");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ const instance = new Temporal.Instant(0n);
const timeZone = "2021-08-19T17:30:45.123456789+01:46[+01:45:30.987654321]";

const result1 = instance.toZonedDateTimeISO(timeZone);
assert.sameValue(result1.timeZone.id, "+01:45:30.987654321", "Time zone string determined from bracket name");
assert.sameValue(result1.timeZoneId, "+01:45:30.987654321", "Time zone string determined from bracket name");
const result2 = instance.toZonedDateTimeISO({ timeZone });
assert.sameValue(result2.timeZone.id, "+01:45:30.987654321", "Time zone string determined from bracket name");
assert.sameValue(result2.timeZoneId, "+01:45:30.987654321", "Time zone string determined from bracket name");
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ const instance = new Temporal.Instant(0n);

["UTC", "+01:30"].forEach((timeZone) => {
const result = instance.toZonedDateTimeISO(timeZone);
assert.sameValue(result.timeZone.id, timeZone, `Time zone created from string "${timeZone}"`);
assert.sameValue(result.getISOFields().timeZone, timeZone, `time zone slot should store string "${timeZone}"`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ Object.defineProperty(Temporal.TimeZone, "from", {
const systemTimeZone = Temporal.Now.timeZoneId();

const resultExplicit = Temporal.Now.zonedDateTime('iso8601', undefined);
assert.sameValue(resultExplicit.timeZone.id, systemTimeZone);
assert.sameValue(resultExplicit.getISOFields().timeZone, systemTimeZone, "time zone slot should store a string");

assert.compareArray(actual, expected, "Temporal.TimeZone.from should not be called");

const resultImplicit = Temporal.Now.zonedDateTime('iso8601');
assert.sameValue(resultImplicit.timeZone.id, systemTimeZone);
assert.sameValue(resultImplicit.getISOFields().timeZone, systemTimeZone, "time zone slot should store a string");

assert.compareArray(actual, expected, "Temporal.TimeZone.from should not be called");
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ features: [Temporal]

const timeZone = 'UtC';
const result = Temporal.Now.zonedDateTime("iso8601", timeZone);
assert.sameValue(result.timeZone.id, 'UTC', `Time zone created from string "${timeZone}"`);
assert.sameValue(result.timeZoneId, 'UTC', `Time zone created from string "${timeZone}"`);
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@ assert.throws(RangeError, () => Temporal.Now.zonedDateTime("iso8601", { timeZone

timeZone = "2021-08-19T17:30Z";
const result1 = Temporal.Now.zonedDateTime("iso8601", timeZone);
assert.sameValue(result1.timeZone.id, "UTC", "date-time + Z is UTC time zone");
assert.sameValue(result1.timeZoneId, "UTC", "date-time + Z is UTC time zone");
const result2 = Temporal.Now.zonedDateTime("iso8601", { timeZone });
assert.sameValue(result2.timeZone.id, "UTC", "date-time + Z is UTC time zone (string in property bag)");
assert.sameValue(result2.timeZoneId, "UTC", "date-time + Z is UTC time zone (string in property bag)");

timeZone = "2021-08-19T17:30-07:00";
const result3 = Temporal.Now.zonedDateTime("iso8601", timeZone);
assert.sameValue(result3.timeZone.id, "-07:00", "date-time + offset is the offset time zone");
assert.sameValue(result3.timeZoneId, "-07:00", "date-time + offset is the offset time zone");
const result4 = Temporal.Now.zonedDateTime("iso8601", { timeZone });
assert.sameValue(result4.timeZone.id, "-07:00", "date-time + offset is the offset time zone (string in property bag)");
assert.sameValue(result4.timeZoneId, "-07:00", "date-time + offset is the offset time zone (string in property bag)");

timeZone = "2021-08-19T17:30[UTC]";
const result5 = Temporal.Now.zonedDateTime("iso8601", timeZone);
assert.sameValue(result5.timeZone.id, "UTC", "date-time + IANA annotation is the IANA time zone");
assert.sameValue(result5.timeZoneId, "UTC", "date-time + IANA annotation is the IANA time zone");
const result6 = Temporal.Now.zonedDateTime("iso8601", { timeZone });
assert.sameValue(result6.timeZone.id, "UTC", "date-time + IANA annotation is the IANA time zone (string in property bag)");
assert.sameValue(result6.timeZoneId, "UTC", "date-time + IANA annotation is the IANA time zone (string in property bag)");

timeZone = "2021-08-19T17:30Z[UTC]";
const result7 = Temporal.Now.zonedDateTime("iso8601", timeZone);
assert.sameValue(result7.timeZone.id, "UTC", "date-time + Z + IANA annotation is the IANA time zone");
assert.sameValue(result7.timeZoneId, "UTC", "date-time + Z + IANA annotation is the IANA time zone");
const result8 = Temporal.Now.zonedDateTime("iso8601", { timeZone });
assert.sameValue(result8.timeZone.id, "UTC", "date-time + Z + IANA annotation is the IANA time zone (string in property bag)");
assert.sameValue(result8.timeZoneId, "UTC", "date-time + Z + IANA annotation is the IANA time zone (string in property bag)");

timeZone = "2021-08-19T17:30-07:00[UTC]";
const result9 = Temporal.Now.zonedDateTime("iso8601", timeZone);
assert.sameValue(result9.timeZone.id, "UTC", "date-time + offset + IANA annotation is the IANA time zone");
assert.sameValue(result9.timeZoneId, "UTC", "date-time + offset + IANA annotation is the IANA time zone");
const result10 = Temporal.Now.zonedDateTime("iso8601", { timeZone });
assert.sameValue(result10.timeZone.id, "UTC", "date-time + offset + IANA annotation is the IANA time zone (string in property bag)");
assert.sameValue(result10.timeZoneId, "UTC", "date-time + offset + IANA annotation is the IANA time zone (string in property bag)");
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ features: [Temporal]
let timeZone = "2016-12-31T23:59:60+00:00[UTC]";

const result1 = Temporal.Now.zonedDateTime("iso8601", timeZone);
assert.sameValue(result1.timeZone.id, "UTC", "leap second is a valid ISO string for TimeZone");
assert.sameValue(result1.timeZoneId, "UTC", "leap second is a valid ISO string for TimeZone");
const result2 = Temporal.Now.zonedDateTime("iso8601", { timeZone });
assert.sameValue(result2.timeZone.id, "UTC", "leap second is a valid ISO string for TimeZone (nested property)");
assert.sameValue(result2.timeZoneId, "UTC", "leap second is a valid ISO string for TimeZone (nested property)");

timeZone = "2021-08-19T17:30:45.123456789+23:59[+23:59:60]";
assert.throws(RangeError, () => Temporal.Now.zonedDateTime("iso8601", timeZone), "leap second in time zone name not valid");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ features: [Temporal]
const timeZone = "2021-08-19T17:30:45.123456789+01:46[+01:45:30.987654321]";

const result1 = Temporal.Now.zonedDateTime("iso8601", timeZone);
assert.sameValue(result1.timeZone.id, "+01:45:30.987654321", "Time zone string determined from bracket name");
assert.sameValue(result1.timeZoneId, "+01:45:30.987654321", "Time zone string determined from bracket name");
const result2 = Temporal.Now.zonedDateTime("iso8601", { timeZone });
assert.sameValue(result2.timeZone.id, "+01:45:30.987654321", "Time zone string determined from bracket name");
assert.sameValue(result2.timeZoneId, "+01:45:30.987654321", "Time zone string determined from bracket name");
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ features: [Temporal]

["UTC", "+01:30"].forEach((timeZone) => {
const result = Temporal.Now.zonedDateTime("iso8601", timeZone);
assert.sameValue(result.timeZone.id, timeZone, `Time zone created from string "${timeZone}"`);
assert.sameValue(result.getISOFields().timeZone, timeZone, `Time zone created from string "${timeZone}"`);
});
3 changes: 1 addition & 2 deletions test/built-ins/Temporal/Now/zonedDateTimeISO/return-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ const zdt = Temporal.Now.zonedDateTimeISO();
const tz = Temporal.Now.timeZoneId();
assert(zdt instanceof Temporal.ZonedDateTime);
assert.sameValue(zdt.getISOFields().calendar, "iso8601", "calendar slot should store a string");
assert(zdt.timeZone instanceof Temporal.TimeZone);
assert.sameValue(zdt.timeZone.id, tz);
assert.sameValue(zdt.getISOFields().timeZone, tz, "time zone slot should store a string");
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ Object.defineProperty(Temporal.TimeZone, "from", {
const systemTimeZone = Temporal.Now.timeZoneId();

const resultExplicit = Temporal.Now.zonedDateTimeISO(undefined);
assert.sameValue(resultExplicit.timeZone.id, systemTimeZone);
assert.sameValue(resultExplicit.getISOFields().timeZone, systemTimeZone, "time zone slot should store a string");

assert.compareArray(actual, expected, "Temporal.TimeZone.from should not be called");

const resultImplicit = Temporal.Now.zonedDateTimeISO();
assert.sameValue(resultImplicit.timeZone.id, systemTimeZone);
assert.sameValue(resultImplicit.getISOFields().timeZone, systemTimeZone, "time zone slot should store a string");

assert.compareArray(actual, expected, "Temporal.TimeZone.from should not be called");
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ features: [Temporal]

const timeZone = 'UtC';
const result = Temporal.Now.zonedDateTimeISO(timeZone);
assert.sameValue(result.timeZone.id, 'UTC', `Time zone created from string "${timeZone}"`);
assert.sameValue(result.timeZoneId, 'UTC', `Time zone created from string "${timeZone}"`);
Loading

0 comments on commit 6c71cf6

Please sign in to comment.