Run prettier for easier review of later commits

This commit is contained in:
Justin Grant 2022-12-16 04:54:25 -08:00 committed by Richard Gibson
parent 9821def022
commit f999dea7c0
6 changed files with 319 additions and 251 deletions

View File

@ -1,4 +1,3 @@
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
@ -9,15 +8,14 @@ includes: [deepEqual.js]
features: [Temporal]
---*/
//should return an Array"
// should return an Array
assert(Array.isArray(Intl.DateTimeFormat.supportedLocalesOf()));
var onlyOnce = value => {
var onlyOnce = (value) => {
var obj = {
calls: 0,
toString() {
if (++this.calls > 1)
throw new RangeError("prop read twice");
if (++this.calls > 1) throw new RangeError("prop read twice");
return value;
}
};
@ -28,8 +26,7 @@ var optionsUS = {
calls: 0,
value: "America/New_York",
get timeZone() {
if (++this.calls > 1)
throw new RangeError("prop read twice");
if (++this.calls > 1) throw new RangeError("prop read twice");
return this.value;
},
set timeZone(val) {
@ -54,41 +51,41 @@ var t2 = "2020-02-20T15:44:56-05:00[America/New_York]";
var start = new Date("1922-12-30");
var end = new Date("1991-12-26");
//should work for Instant
// should work for Instant
assert.sameValue(us.format(Temporal.Instant.from(t1)), "11/18/1976, 9:23:30 AM");
assert.sameValue(at.format(Temporal.Instant.from(t1)), "18.11.1976, 15:23:30");
//should work for ZonedDateTime
// should work for ZonedDateTime
assert.sameValue(us2.format(Temporal.ZonedDateTime.from(t1)), "11/18/1976, 2:23:30 PM UTC");
assert.sameValue(at2.format(Temporal.ZonedDateTime.from(t1)), "18.11.1976, 14:23:30 UTC");
//should work for DateTime
// should work for DateTime
assert.sameValue(us.format(Temporal.PlainDateTime.from(t1)), "11/18/1976, 2:23:30 PM");
assert.sameValue(at.format(Temporal.PlainDateTime.from(t1)), "18.11.1976, 14:23:30");
//should work for Time
// should work for Time
assert.sameValue(us.format(Temporal.PlainTime.from(t1)), "2:23:30 PM");
assert.sameValue(at.format(Temporal.PlainTime.from(t1)), "14:23:30");
//should work for Date
// should work for Date
assert.sameValue(us.format(Temporal.PlainDate.from(t1)), "11/18/1976");
assert.sameValue(at.format(Temporal.PlainDate.from(t1)), "18.11.1976");
//should work for YearMonth
// should work for YearMonth
var t = Temporal.PlainDate.from(t1);
assert.sameValue(us.format(t.withCalendar(usCalendar).toPlainYearMonth()), "11/1976");
assert.sameValue(at.format(t.withCalendar(atCalendar).toPlainYearMonth()), "11.1976");
//should work for MonthDay
// should work for MonthDay
var t = Temporal.PlainDate.from(t1);
assert.sameValue(us.format(t.withCalendar(usCalendar).toPlainMonthDay()), "11/18");
assert.sameValue(at.format(t.withCalendar(atCalendar).toPlainMonthDay()), "18.11.");
//should not break legacy Date
// should not break legacy Date
assert.sameValue(us.format(start), "12/29/1922");
assert.sameValue(at.format(start), "30.12.1922");
//should work for Instant
// should work for Instant
assert.deepEqual(us.formatToParts(Temporal.Instant.from(t2)), [
{
type: "month",
@ -189,7 +186,7 @@ assert.deepEqual(at.formatToParts(Temporal.Instant.from(t2)), [
value: "56"
}
]);
//should work for ZonedDateTime
// should work for ZonedDateTime
assert.deepEqual(us2.formatToParts(Temporal.ZonedDateTime.from(t2)), [
{
type: "month",
@ -306,7 +303,7 @@ assert.deepEqual(at2.formatToParts(Temporal.ZonedDateTime.from(t2)), [
value: "GMT-5"
}
]);
//should work for DateTime
// should work for DateTime
assert.deepEqual(us.formatToParts(Temporal.PlainDateTime.from(t2)), [
{
type: "month",
@ -407,7 +404,7 @@ assert.deepEqual(at.formatToParts(Temporal.PlainDateTime.from(t2)), [
value: "56"
}
]);
//should work for Time
// should work for Time
assert.deepEqual(us.formatToParts(Temporal.PlainTime.from(t2)), [
{
type: "hour",
@ -460,7 +457,7 @@ assert.deepEqual(at.formatToParts(Temporal.PlainTime.from(t2)), [
value: "56"
}
]);
//should work for Date
// should work for Date
assert.deepEqual(us.formatToParts(Temporal.PlainDate.from(t2)), [
{
type: "month",
@ -505,7 +502,7 @@ assert.deepEqual(at.formatToParts(Temporal.PlainDate.from(t2)), [
value: "2020"
}
]);
//should work for YearMonth
// should work for YearMonth
var t = Temporal.PlainDate.from(t2);
assert.deepEqual(us.formatToParts(t.withCalendar(usCalendar).toPlainYearMonth()), [
{
@ -535,7 +532,7 @@ assert.deepEqual(at.formatToParts(t.withCalendar(atCalendar).toPlainYearMonth())
value: "2020"
}
]);
//should work for MonthDay
// should work for MonthDay
var t = Temporal.PlainDate.from(t2);
assert.deepEqual(us.formatToParts(t.withCalendar(usCalendar).toPlainMonthDay()), [
{
@ -569,7 +566,7 @@ assert.deepEqual(at.formatToParts(t.withCalendar(atCalendar).toPlainMonthDay()),
value: "."
}
]);
//should not break legacy Date
// should not break legacy Date
assert.deepEqual(us.formatToParts(end), [
{
type: "month",
@ -614,55 +611,92 @@ assert.deepEqual(at.formatToParts(end), [
value: "1991"
}
]);
//formatRange
//should work for Instant
assert.sameValue(us.formatRange(Temporal.Instant.from(t1), Temporal.Instant.from(t2)), "11/18/1976, 9:23:30 AM \u2013 2/20/2020, 3:44:56 PM");
assert.sameValue(at.formatRange(Temporal.Instant.from(t1), Temporal.Instant.from(t2)), "18.11.1976, 15:23:30 \u2013 20.2.2020, 21:44:56");
// formatRange
// should work for Instant
assert.sameValue(
us.formatRange(Temporal.Instant.from(t1), Temporal.Instant.from(t2)),
"11/18/1976, 9:23:30 AM \u2013 2/20/2020, 3:44:56 PM"
);
assert.sameValue(
at.formatRange(Temporal.Instant.from(t1), Temporal.Instant.from(t2)),
"18.11.1976, 15:23:30 \u2013 20.2.2020, 21:44:56"
);
//should work for ZonedDateTime
// should work for ZonedDateTime
var zdt1 = Temporal.ZonedDateTime.from(t1);
var zdt2 = Temporal.ZonedDateTime.from(t2).withTimeZone(zdt1.timeZone);
assert.sameValue(us2.formatRange(zdt1, zdt2), "11/18/1976, 2:23:30 PM UTC \u2013 2/20/2020, 8:44:56 PM UTC");
assert.sameValue(at2.formatRange(zdt1, zdt2), "18.11.1976, 14:23:30 UTC \u2013 20.2.2020, 20:44:56 UTC");
//should work for DateTime
assert.sameValue(us.formatRange(Temporal.PlainDateTime.from(t1), Temporal.PlainDateTime.from(t2)), "11/18/1976, 2:23:30 PM \u2013 2/20/2020, 3:44:56 PM");
assert.sameValue(at.formatRange(Temporal.PlainDateTime.from(t1), Temporal.PlainDateTime.from(t2)), "18.11.1976, 14:23:30 \u2013 20.2.2020, 15:44:56");
// should work for DateTime
assert.sameValue(
us.formatRange(Temporal.PlainDateTime.from(t1), Temporal.PlainDateTime.from(t2)),
"11/18/1976, 2:23:30 PM \u2013 2/20/2020, 3:44:56 PM"
);
assert.sameValue(
at.formatRange(Temporal.PlainDateTime.from(t1), Temporal.PlainDateTime.from(t2)),
"18.11.1976, 14:23:30 \u2013 20.2.2020, 15:44:56"
);
//should work for Time
assert.sameValue(us.formatRange(Temporal.PlainTime.from(t1), Temporal.PlainTime.from(t2)), "2:23:30 PM \u2013 3:44:56 PM");
// should work for Time
assert.sameValue(
us.formatRange(Temporal.PlainTime.from(t1), Temporal.PlainTime.from(t2)),
"2:23:30 PM \u2013 3:44:56 PM"
);
assert.sameValue(at.formatRange(Temporal.PlainTime.from(t1), Temporal.PlainTime.from(t2)), "14:23:30 \u2013 15:44:56");
//should work for Date
assert.sameValue(us.formatRange(Temporal.PlainDate.from(t1), Temporal.PlainDate.from(t2)), "11/18/1976 \u2013 2/20/2020");
assert.sameValue(at.formatRange(Temporal.PlainDate.from(t1), Temporal.PlainDate.from(t2)), "18.11.1976 \u2013 20.02.2020");
// should work for Date
assert.sameValue(
us.formatRange(Temporal.PlainDate.from(t1), Temporal.PlainDate.from(t2)),
"11/18/1976 \u2013 2/20/2020"
);
assert.sameValue(
at.formatRange(Temporal.PlainDate.from(t1), Temporal.PlainDate.from(t2)),
"18.11.1976 \u2013 20.02.2020"
);
//should work for YearMonth
// should work for YearMonth
var date1 = Temporal.PlainDate.from(t1);
var date2 = Temporal.PlainDate.from(t2);
assert.sameValue(us.formatRange(date1.withCalendar(usCalendar).toPlainYearMonth(), date2.withCalendar(usCalendar).toPlainYearMonth()), "11/1976 \u2013 2/2020");
assert.sameValue(at.formatRange(date1.withCalendar(atCalendar).toPlainYearMonth(), date2.withCalendar(atCalendar).toPlainYearMonth()), "11.1976 \u2013 02.2020");
assert.sameValue(
us.formatRange(date1.withCalendar(usCalendar).toPlainYearMonth(), date2.withCalendar(usCalendar).toPlainYearMonth()),
"11/1976 \u2013 2/2020"
);
assert.sameValue(
at.formatRange(date1.withCalendar(atCalendar).toPlainYearMonth(), date2.withCalendar(atCalendar).toPlainYearMonth()),
"11.1976 \u2013 02.2020"
);
//should work for MonthDay
// should work for MonthDay
var date1 = Temporal.PlainDate.from(t1);
var date2 = Temporal.PlainDate.from(t2);
assert.sameValue(us.formatRange(date2.withCalendar(usCalendar).toPlainMonthDay(), date1.withCalendar(usCalendar).toPlainMonthDay()), "2/20 \u2013 11/18");
assert.sameValue(at.formatRange(date2.withCalendar(atCalendar).toPlainMonthDay(), date1.withCalendar(atCalendar).toPlainMonthDay()), "20.02. \u2013 18.11.");
assert.sameValue(
us.formatRange(date2.withCalendar(usCalendar).toPlainMonthDay(), date1.withCalendar(usCalendar).toPlainMonthDay()),
"2/20 \u2013 11/18"
);
assert.sameValue(
at.formatRange(date2.withCalendar(atCalendar).toPlainMonthDay(), date1.withCalendar(atCalendar).toPlainMonthDay()),
"20.02. \u2013 18.11."
);
//should not break legacy Date
// should not break legacy Date
assert.sameValue(us.formatRange(start, end), "12/29/1922 \u2013 12/25/1991");
assert.sameValue(at.formatRange(start, end), "30.12.1922 \u2013 26.12.1991");
//should throw a TypeError when called with dissimilar types", () => assert.throws(TypeError, () => us.formatRange(Temporal.Instant.from(t1), Temporal.PlainDateTime.from(t2))));
//should throw a RangeError when called with different calendars
assert.throws(RangeError, () => us.formatRange(Temporal.PlainDateTime.from(t1), Temporal.PlainDateTime.from(t2).withCalendar("japanese")));
assert.throws(RangeError, () => us.formatRange(Temporal.PlainDate.from(t1), Temporal.PlainDate.from(t2).withCalendar("japanese")));
// should throw a TypeError when called with dissimilar types", () => assert.throws(TypeError, () => us.formatRange(Temporal.Instant.from(t1), Temporal.PlainDateTime.from(t2))));
// should throw a RangeError when called with different calendars
assert.throws(RangeError, () =>
us.formatRange(Temporal.PlainDateTime.from(t1), Temporal.PlainDateTime.from(t2).withCalendar("japanese"))
);
assert.throws(RangeError, () =>
us.formatRange(Temporal.PlainDate.from(t1), Temporal.PlainDate.from(t2).withCalendar("japanese"))
);
//throws for two ZonedDateTimes with different time zones
// throws for two ZonedDateTimes with different time zones
assert.throws(RangeError, () => us2.formatRange(Temporal.ZonedDateTime.from(t1), Temporal.ZonedDateTime.from(t2)));
//formatRangeToParts
//should work for Instant
// formatRangeToParts
// should work for Instant
assert.deepEqual(us.formatRangeToParts(Temporal.Instant.from(t1), Temporal.Instant.from(t2)), [
{
type: "month",
@ -918,7 +952,7 @@ assert.deepEqual(at.formatRangeToParts(Temporal.Instant.from(t1), Temporal.Insta
}
]);
//should work for ZonedDateTime
// should work for ZonedDateTime
var zdt1 = Temporal.ZonedDateTime.from(t1);
var zdt2 = Temporal.ZonedDateTime.from(t2).withTimeZone(zdt1.timeZone);
assert.deepEqual(us2.formatRangeToParts(zdt1, zdt2), [
@ -1215,7 +1249,7 @@ assert.deepEqual(at2.formatRangeToParts(zdt1, zdt2), [
source: "endRange"
}
]);
//should work for DateTime
// should work for DateTime
assert.deepEqual(us.formatRangeToParts(Temporal.PlainDateTime.from(t1), Temporal.PlainDateTime.from(t2)), [
{
type: "month",
@ -1470,7 +1504,7 @@ assert.deepEqual(at.formatRangeToParts(Temporal.PlainDateTime.from(t1), Temporal
source: "endRange"
}
]);
//should work for Time
// should work for Time
assert.deepEqual(us.formatRangeToParts(Temporal.PlainTime.from(t1), Temporal.PlainTime.from(t2)), [
{
type: "hour",
@ -1605,7 +1639,7 @@ assert.deepEqual(at.formatRangeToParts(Temporal.PlainTime.from(t1), Temporal.Pla
source: "endRange"
}
]);
//should work for Date
// should work for Date
assert.deepEqual(us.formatRangeToParts(Temporal.PlainDate.from(t1), Temporal.PlainDate.from(t2)), [
{
type: "month",
@ -1720,166 +1754,190 @@ assert.deepEqual(at.formatRangeToParts(Temporal.PlainDate.from(t1), Temporal.Pla
source: "endRange"
}
]);
//should work for YearMonth
// should work for YearMonth
var date1 = Temporal.PlainDate.from(t1);
var date2 = Temporal.PlainDate.from(t2);
assert.deepEqual(us.formatRangeToParts(date1.withCalendar(usCalendar).toPlainYearMonth(), date2.withCalendar(usCalendar).toPlainYearMonth()), [
{
type: "month",
value: "11",
source: "startRange"
},
{
type: "literal",
value: "/",
source: "startRange"
},
{
type: "year",
value: "1976",
source: "startRange"
},
{
type: "literal",
value: " \u2013 ",
source: "shared"
},
{
type: "month",
value: "2",
source: "endRange"
},
{
type: "literal",
value: "/",
source: "endRange"
},
{
type: "year",
value: "2020",
source: "endRange"
}
]);
assert.deepEqual(at.formatRangeToParts(date1.withCalendar(atCalendar).toPlainYearMonth(), date2.withCalendar(atCalendar).toPlainYearMonth()), [
{
type: "month",
value: "11",
source: "startRange"
},
{
type: "literal",
value: ".",
source: "startRange"
},
{
type: "year",
value: "1976",
source: "startRange"
},
{
type: "literal",
value: " \u2013 ",
source: "shared"
},
{
type: "month",
value: "02",
source: "endRange"
},
{
type: "literal",
value: ".",
source: "endRange"
},
{
type: "year",
value: "2020",
source: "endRange"
}
]);
//should work for MonthDay
assert.deepEqual(
us.formatRangeToParts(
date1.withCalendar(usCalendar).toPlainYearMonth(),
date2.withCalendar(usCalendar).toPlainYearMonth()
),
[
{
type: "month",
value: "11",
source: "startRange"
},
{
type: "literal",
value: "/",
source: "startRange"
},
{
type: "year",
value: "1976",
source: "startRange"
},
{
type: "literal",
value: " \u2013 ",
source: "shared"
},
{
type: "month",
value: "2",
source: "endRange"
},
{
type: "literal",
value: "/",
source: "endRange"
},
{
type: "year",
value: "2020",
source: "endRange"
}
]
);
assert.deepEqual(
at.formatRangeToParts(
date1.withCalendar(atCalendar).toPlainYearMonth(),
date2.withCalendar(atCalendar).toPlainYearMonth()
),
[
{
type: "month",
value: "11",
source: "startRange"
},
{
type: "literal",
value: ".",
source: "startRange"
},
{
type: "year",
value: "1976",
source: "startRange"
},
{
type: "literal",
value: " \u2013 ",
source: "shared"
},
{
type: "month",
value: "02",
source: "endRange"
},
{
type: "literal",
value: ".",
source: "endRange"
},
{
type: "year",
value: "2020",
source: "endRange"
}
]
);
// should work for MonthDay
var date1 = Temporal.PlainDate.from(t1);
var date2 = Temporal.PlainDate.from(t2);
assert.deepEqual(us.formatRangeToParts(date2.withCalendar(usCalendar).toPlainMonthDay(), date1.withCalendar(usCalendar).toPlainMonthDay()), [
{
type: "month",
value: "2",
source: "startRange"
},
{
type: "literal",
value: "/",
source: "startRange"
},
{
type: "day",
value: "20",
source: "startRange"
},
{
type: "literal",
value: " \u2013 ",
source: "shared"
},
{
type: "month",
value: "11",
source: "endRange"
},
{
type: "literal",
value: "/",
source: "endRange"
},
{
type: "day",
value: "18",
source: "endRange"
}
]);
assert.deepEqual(at.formatRangeToParts(date2.withCalendar(atCalendar).toPlainMonthDay(), date1.withCalendar(atCalendar).toPlainMonthDay()), [
{
type: "day",
value: "20",
source: "startRange"
},
{
type: "literal",
value: ".",
source: "startRange"
},
{
type: "month",
value: "02",
source: "startRange"
},
{
type: "literal",
value: ". \u2013 ",
source: "shared"
},
{
type: "day",
value: "18",
source: "endRange"
},
{
type: "literal",
value: ".",
source: "endRange"
},
{
type: "month",
value: "11",
source: "endRange"
},
{
type: "literal",
value: ".",
source: "shared"
}
]);
//should not break legacy Date
assert.deepEqual(
us.formatRangeToParts(
date2.withCalendar(usCalendar).toPlainMonthDay(),
date1.withCalendar(usCalendar).toPlainMonthDay()
),
[
{
type: "month",
value: "2",
source: "startRange"
},
{
type: "literal",
value: "/",
source: "startRange"
},
{
type: "day",
value: "20",
source: "startRange"
},
{
type: "literal",
value: " \u2013 ",
source: "shared"
},
{
type: "month",
value: "11",
source: "endRange"
},
{
type: "literal",
value: "/",
source: "endRange"
},
{
type: "day",
value: "18",
source: "endRange"
}
]
);
assert.deepEqual(
at.formatRangeToParts(
date2.withCalendar(atCalendar).toPlainMonthDay(),
date1.withCalendar(atCalendar).toPlainMonthDay()
),
[
{
type: "day",
value: "20",
source: "startRange"
},
{
type: "literal",
value: ".",
source: "startRange"
},
{
type: "month",
value: "02",
source: "startRange"
},
{
type: "literal",
value: ". \u2013 ",
source: "shared"
},
{
type: "day",
value: "18",
source: "endRange"
},
{
type: "literal",
value: ".",
source: "endRange"
},
{
type: "month",
value: "11",
source: "endRange"
},
{
type: "literal",
value: ".",
source: "shared"
}
]
);
// should not break legacy Date
assert.deepEqual(us.formatRangeToParts(start, end), [
{
type: "month",
@ -1994,10 +2052,16 @@ assert.deepEqual(at.formatRangeToParts(start, end), [
source: "endRange"
}
]);
//should throw a TypeError when called with dissimilar types
// should throw a TypeError when called with dissimilar types
assert.throws(TypeError, () => at.formatRangeToParts(Temporal.Instant.from(t1), Temporal.PlainDateTime.from(t2)));
//should throw a RangeError when called with different calendars
assert.throws(RangeError, () => at.formatRangeToParts(Temporal.PlainDateTime.from(t1), Temporal.PlainDateTime.from(t2).withCalendar("japanese")));
assert.throws(RangeError, () => at.formatRangeToParts(Temporal.PlainDate.from(t1), Temporal.PlainDate.from(t2).withCalendar("japanese")));
//throws for two ZonedDateTimes with different time zones
assert.throws(RangeError, () => us2.formatRangeToParts(Temporal.ZonedDateTime.from(t1), Temporal.ZonedDateTime.from(t2)));
// should throw a RangeError when called with different calendars
assert.throws(RangeError, () =>
at.formatRangeToParts(Temporal.PlainDateTime.from(t1), Temporal.PlainDateTime.from(t2).withCalendar("japanese"))
);
assert.throws(RangeError, () =>
at.formatRangeToParts(Temporal.PlainDate.from(t1), Temporal.PlainDate.from(t2).withCalendar("japanese"))
);
// throws for two ZonedDateTimes with different time zones
assert.throws(RangeError, () =>
us2.formatRangeToParts(Temporal.ZonedDateTime.from(t1), Temporal.ZonedDateTime.from(t2))
);

View File

@ -8,21 +8,21 @@ features: [Temporal]
---*/
function maybeGetWeekdayOnlyFormat() {
const fmt = new Intl.DateTimeFormat('en', { weekday: 'long', timeZone: 'Europe/Vienna' });
const fmt = new Intl.DateTimeFormat("en", { weekday: "long", timeZone: "Europe/Vienna" });
if (
['era', 'year', 'month', 'day', 'hour', 'minute', 'second', 'timeZoneName'].some(
["era", "year", "month", "day", "hour", "minute", "second", "timeZoneName"].some(
(prop) => prop in fmt.resolvedOptions()
)
) {
//no weekday-only format available
// no weekday-only format available
return null;
}
return fmt;
}
var datetime = Temporal.PlainDateTime.from("1976-11-18T15:23:30");
assert.sameValue(`${ datetime.toLocaleString("en", { timeZone: "America/New_York" }) }`, "11/18/1976, 3:23:30 PM")
assert.sameValue(`${ datetime.toLocaleString("de", { timeZone: "Europe/Vienna" }) }`, "18.11.1976, 15:23:30")
assert.sameValue(`${datetime.toLocaleString("en", { timeZone: "America/New_York" })}`, "11/18/1976, 3:23:30 PM");
assert.sameValue(`${datetime.toLocaleString("de", { timeZone: "Europe/Vienna" })}`, "18.11.1976, 15:23:30");
var fmt = maybeGetWeekdayOnlyFormat();
if (fmt) assert.sameValue(fmt.format(datetime), "Thursday");
@ -31,7 +31,7 @@ assert.sameValue(datetime.toLocaleString("en", { timeZoneName: "long" }), "11/18
// should use compatible disambiguation option
var dstStart = new Temporal.PlainDateTime(2020, 3, 8, 2, 30);
assert.sameValue(`${ dstStart.toLocaleString("en", { timeZone: "America/Los_Angeles" }) }`, "3/8/2020, 3:30:00 AM");
assert.sameValue(`${dstStart.toLocaleString("en", { timeZone: "America/Los_Angeles" })}`, "3/8/2020, 3:30:00 AM");
// works when the object's calendar is the same as the locale's calendar
var dt = Temporal.PlainDateTime.from({

View File

@ -8,24 +8,23 @@ features: [Temporal]
---*/
function maybeGetWeekdayOnlyFormat() {
const fmt = new Intl.DateTimeFormat('en', { weekday: 'long', timeZone: 'Europe/Vienna' });
const fmt = new Intl.DateTimeFormat("en", { weekday: "long", timeZone: "Europe/Vienna" });
if (
['era', 'year', 'month', 'day', 'hour', 'minute', 'second', 'timeZoneName'].some(
["era", "year", "month", "day", "hour", "minute", "second", "timeZoneName"].some(
(prop) => prop in fmt.resolvedOptions()
)
) {
//no weekday-only format available
// no weekday-only format available
return null;
}
return fmt;
}
var instant = Temporal.Instant.from("1976-11-18T14:23:30Z");
assert.sameValue(`${ instant.toLocaleString("en", { timeZone: "America/New_York" }) }`, "11/18/1976, 9:23:30 AM")
assert.sameValue(`${ instant.toLocaleString("de", { timeZone: "Europe/Vienna" }) }`, "18.11.1976, 15:23:30")
assert.sameValue(`${instant.toLocaleString("en", { timeZone: "America/New_York" })}`, "11/18/1976, 9:23:30 AM");
assert.sameValue(`${instant.toLocaleString("de", { timeZone: "Europe/Vienna" })}`, "18.11.1976, 15:23:30");
var fmt = maybeGetWeekdayOnlyFormat();
if (fmt)
assert.sameValue(fmt.format(instant), "Thursday");
if (fmt) assert.sameValue(fmt.format(instant), "Thursday");
// outputs timeZoneName if requested
var str = instant.toLocaleString("en", {

View File

@ -8,8 +8,8 @@ features: [Temporal]
---*/
var time = Temporal.PlainTime.from("1976-11-18T15:23:30");
assert.sameValue(`${ time.toLocaleString("en", { timeZone: "America/New_York" }) }`, "3:23:30 PM")
assert.sameValue(`${ time.toLocaleString("de", { timeZone: "Europe/Vienna" }) }`, "15:23:30")
assert.sameValue(`${time.toLocaleString("en", { timeZone: "America/New_York" })}`, "3:23:30 PM");
assert.sameValue(`${time.toLocaleString("de", { timeZone: "Europe/Vienna" })}`, "15:23:30");
// should ignore units not in the data type
assert.sameValue(time.toLocaleString("en", { timeZoneName: "long" }), "3:23:30 PM");

View File

@ -1,4 +1,3 @@
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
@ -14,11 +13,14 @@ var yearmonth = Temporal.PlainYearMonth.from({
month: 11,
calendar
});
assert.sameValue(`${ yearmonth.toLocaleString("en", { timeZone: "America/New_York" }) }`, "11/1976")
assert.sameValue(`${ yearmonth.toLocaleString("de", {
timeZone: "Europe/Vienna",
calendar
}) }`, "11.1976")
assert.sameValue(`${yearmonth.toLocaleString("en", { timeZone: "America/New_York" })}`, "11/1976");
assert.sameValue(
`${yearmonth.toLocaleString("de", {
timeZone: "Europe/Vienna",
calendar
})}`,
"11.1976"
);
// should ignore units not in the data type
assert.sameValue(yearmonth.toLocaleString("en", { timeZoneName: "long" }), "11/1976");

View File

@ -8,27 +8,30 @@ features: [Temporal]
---*/
function maybeGetWeekdayOnlyFormat() {
const fmt = new Intl.DateTimeFormat('en', { weekday: 'long', timeZone: 'Europe/Vienna' });
const fmt = new Intl.DateTimeFormat("en", { weekday: "long", timeZone: "Europe/Vienna" });
if (
['era', 'year', 'month', 'day', 'hour', 'minute', 'second', 'timeZoneName'].some(
["era", "year", "month", "day", "hour", "minute", "second", "timeZoneName"].some(
(prop) => prop in fmt.resolvedOptions()
)
) {
//no weekday-only format available
// no weekday-only format available
return null;
}
return fmt;
}
var zdt = Temporal.ZonedDateTime.from("1976-11-18T15:23:30+01:00[Europe/Vienna]");
assert.sameValue(zdt.toLocaleString("en"), "11/18/1976, 3:23:30 PM GMT+1")
assert.sameValue(zdt.toLocaleString("de"), "18.11.1976, 15:23:30 MEZ")
assert.sameValue(zdt.toLocaleString("en"), "11/18/1976, 3:23:30 PM GMT+1");
assert.sameValue(zdt.toLocaleString("de"), "18.11.1976, 15:23:30 MEZ");
const fmt = maybeGetWeekdayOnlyFormat();
//uses only the options in resolvedOptions
if (fmt) assert.sameValue(fmt.format(zdt), 'Thursday');
// uses only the options in resolvedOptions
if (fmt) assert.sameValue(fmt.format(zdt), "Thursday");
// can override the style of the time zone name
assert.sameValue(zdt.toLocaleString("en", { timeZoneName: "long" }), "11/18/1976, 3:23:30 PM Central European Standard Time");
assert.sameValue(
zdt.toLocaleString("en", { timeZoneName: "long" }),
"11/18/1976, 3:23:30 PM Central European Standard Time"
);
// works if the time zone given in options agrees with the object's time zone
assert.sameValue(zdt.toLocaleString("en", { timeZone: "Europe/Vienna" }), "11/18/1976, 3:23:30 PM GMT+1");