mirror of https://github.com/tc39/test262.git
Add intl in staging directory
This commit is contained in:
parent
c4daf3ef74
commit
747bed2e8a
|
@ -0,0 +1,93 @@
|
|||
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal-intl
|
||||
description: Addition across lunisolar leap months
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
// Adding years across Hebrew leap month
|
||||
var date = Temporal.PlainDate.from({
|
||||
year: 5783,
|
||||
monthCode: "M08",
|
||||
day: 2,
|
||||
calendar: "hebrew"
|
||||
});
|
||||
var added = date.add({ years: 1 });
|
||||
assert.sameValue(added.monthCode, date.monthCode);
|
||||
assert.sameValue(added.year, date.year + 1);
|
||||
|
||||
// Adding months across Hebrew leap month
|
||||
var date = Temporal.PlainDate.from({
|
||||
year: 5783,
|
||||
monthCode: "M08",
|
||||
day: 2,
|
||||
calendar: "hebrew"
|
||||
});
|
||||
var added = date.add({ months: 13 });
|
||||
assert.sameValue(added.monthCode, date.monthCode);
|
||||
assert.sameValue(added.year, date.year + 1);
|
||||
|
||||
// Adding months and years across Hebrew leap month
|
||||
var date = Temporal.PlainDate.from({
|
||||
year: 5783,
|
||||
monthCode: "M08",
|
||||
day: 2,
|
||||
calendar: "hebrew"
|
||||
});
|
||||
var added = date.add({
|
||||
years: 1,
|
||||
months: 12
|
||||
});
|
||||
assert.sameValue(added.monthCode, date.monthCode);
|
||||
assert.sameValue(added.year, date.year + 2);
|
||||
var testChineseData = new Date("2001-02-01T00:00Z").toLocaleString("en-US-u-ca-chinese", {
|
||||
day: "numeric",
|
||||
month: "numeric",
|
||||
year: "numeric",
|
||||
era: "short",
|
||||
timeZone: "UTC"
|
||||
});
|
||||
var hasOutdatedChineseIcuData = !testChineseData.endsWith("2001");
|
||||
|
||||
// Adding years across Chinese leap month"
|
||||
if(hasOutdatedChineseIcuData) {
|
||||
var date = Temporal.PlainDate.from({
|
||||
year: 2000,
|
||||
monthCode: "M08",
|
||||
day: 2,
|
||||
calendar: "chinese"
|
||||
});
|
||||
var added = date.add({ years: 1 });
|
||||
assert.sameValue(added.monthCode, date.monthCode);
|
||||
assert.sameValue(added.year, date.year + 1);
|
||||
}
|
||||
// Adding months across Chinese leap month
|
||||
if(hasOutdatedChineseIcuData) {
|
||||
var date = Temporal.PlainDate.from({
|
||||
year: 2000,
|
||||
monthCode: "M08",
|
||||
day: 2,
|
||||
calendar: "chinese"
|
||||
});
|
||||
var added = date.add({ months: 13 });
|
||||
assert.sameValue(added.monthCode, date.monthCode);
|
||||
assert.sameValue(added.year, date.year + 1);
|
||||
}
|
||||
|
||||
// Adding months and years across Chinese leap month
|
||||
if(hasOutdatedChineseIcuData) {
|
||||
var date = Temporal.PlainDate.from({
|
||||
year: 2001,
|
||||
monthCode: "M08",
|
||||
day: 2,
|
||||
calendar: "chinese"
|
||||
});
|
||||
var added = date.add({
|
||||
years: 1,
|
||||
months: 12
|
||||
});
|
||||
assert.sameValue(added.monthCode, date.monthCode);
|
||||
assert.sameValue(added.year, date.year + 2);
|
||||
};
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,58 @@
|
|||
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal-intl
|
||||
description: date.toLocaleString()
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
function maybeGetWeekdayOnlyFormat() {
|
||||
const fmt = new Intl.DateTimeFormat('en', { weekday: 'long', timeZone: 'Europe/Vienna' });
|
||||
if (
|
||||
['era', 'year', 'month', 'day', 'hour', 'minute', 'second', 'timeZoneName'].some(
|
||||
(prop) => prop in fmt.resolvedOptions()
|
||||
)
|
||||
) {
|
||||
//no weekday-only format available
|
||||
return null;
|
||||
}
|
||||
return fmt;
|
||||
}
|
||||
|
||||
var date = Temporal.PlainDate.from("1976-11-18T15:23:30");
|
||||
assert.sameValue(`${ date.toLocaleString("en", { timeZone: "America/New_York" }) }`, "11/18/1976")
|
||||
assert.sameValue(`${ date.toLocaleString("de", { timeZone: "Europe/Vienna" }) }`, "18.11.1976")
|
||||
var fmt = maybeGetWeekdayOnlyFormat();
|
||||
if (fmt) assert.sameValue(fmt.format(date), "Thursday");
|
||||
|
||||
// should ignore units not in the data type
|
||||
assert.sameValue(date.toLocaleString("en", { timeZoneName: "long" }), "11/18/1976");
|
||||
assert.sameValue(date.toLocaleString("en", { hour: "numeric" }), "11/18/1976");
|
||||
assert.sameValue(date.toLocaleString("en", { minute: "numeric" }), "11/18/1976");
|
||||
assert.sameValue(date.toLocaleString("en", { second: "numeric" }), "11/18/1976");
|
||||
|
||||
// works when the object's calendar is the same as the locale's calendar
|
||||
var d = Temporal.PlainDate.from({
|
||||
era: "showa",
|
||||
eraYear: 51,
|
||||
month: 11,
|
||||
day: 18,
|
||||
calendar: "japanese"
|
||||
});
|
||||
var result = d.toLocaleString("en-US-u-ca-japanese");
|
||||
assert(result === "11/18/51" || result === "11/18/51 S");
|
||||
|
||||
// adopts the locale's calendar when the object's calendar is ISO
|
||||
var d = Temporal.PlainDate.from("1976-11-18");
|
||||
var result = d.toLocaleString("en-US-u-ca-japanese");
|
||||
assert(result === "11/18/51" || result === "11/18/51 S");
|
||||
|
||||
// throws when the calendars are different and not ISO
|
||||
var d = Temporal.PlainDate.from({
|
||||
year: 1976,
|
||||
month: 11,
|
||||
day: 18,
|
||||
calendar: "gregory"
|
||||
});
|
||||
assert.throws(RangeError, () => d.toLocaleString("en-US-u-ca-japanese"));
|
|
@ -0,0 +1,65 @@
|
|||
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal-intl
|
||||
description: datetime.toLocaleString()
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
function maybeGetWeekdayOnlyFormat() {
|
||||
const fmt = new Intl.DateTimeFormat('en', { weekday: 'long', timeZone: 'Europe/Vienna' });
|
||||
if (
|
||||
['era', 'year', 'month', 'day', 'hour', 'minute', 'second', 'timeZoneName'].some(
|
||||
(prop) => prop in fmt.resolvedOptions()
|
||||
)
|
||||
) {
|
||||
//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")
|
||||
var fmt = maybeGetWeekdayOnlyFormat();
|
||||
if (fmt) assert.sameValue(fmt.format(datetime), "Thursday");
|
||||
|
||||
// should ignore units not in the data type
|
||||
assert.sameValue(datetime.toLocaleString("en", { timeZoneName: "long" }), "11/18/1976, 3:23:30 PM");
|
||||
|
||||
// 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");
|
||||
|
||||
// works when the object's calendar is the same as the locale's calendar
|
||||
var dt = Temporal.PlainDateTime.from({
|
||||
era: "showa",
|
||||
eraYear: 51,
|
||||
month: 11,
|
||||
day: 18,
|
||||
hour: 15,
|
||||
minute: 23,
|
||||
second: 30,
|
||||
calendar: "japanese"
|
||||
});
|
||||
var result = dt.toLocaleString("en-US-u-ca-japanese");
|
||||
assert(result === "11/18/51, 3:23:30 PM" || result === "11/18/51 S, 3:23:30 PM");
|
||||
|
||||
// adopts the locale's calendar when the object's calendar is ISO
|
||||
var dt = Temporal.PlainDateTime.from("1976-11-18T15:23:30");
|
||||
var result = dt.toLocaleString("en-US-u-ca-japanese");
|
||||
assert(result === "11/18/51, 3:23:30 PM" || result === "11/18/51 S, 3:23:30 PM");
|
||||
|
||||
// throws when the calendars are different and not ISO
|
||||
var dt = Temporal.PlainDateTime.from({
|
||||
year: 1976,
|
||||
month: 11,
|
||||
day: 18,
|
||||
hour: 15,
|
||||
minute: 23,
|
||||
second: 30,
|
||||
calendar: "gregory"
|
||||
});
|
||||
assert.throws(RangeError, () => dt.toLocaleString("en-US-u-ca-japanese"));
|
|
@ -0,0 +1,79 @@
|
|||
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal-intl
|
||||
description: Hebrew leap months
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
// Valid leap month: Adar I 5779
|
||||
var date = Temporal.PlainDate.from({
|
||||
year: 5779,
|
||||
month: 6,
|
||||
day: 1,
|
||||
calendar: "hebrew"
|
||||
});
|
||||
assert.sameValue(date.month, 6);
|
||||
assert.sameValue(date.monthCode, "M05L");
|
||||
assert.sameValue(date.day, 1);
|
||||
date = Temporal.PlainDate.from({
|
||||
year: 5779,
|
||||
monthCode: "M05L",
|
||||
day: 1,
|
||||
calendar: "hebrew"
|
||||
});
|
||||
assert.sameValue(date.month, 6);
|
||||
assert.sameValue(date.monthCode, "M05L");
|
||||
assert.sameValue(date.day, 1);
|
||||
|
||||
// Creating dates in later months in a leap year
|
||||
var date = Temporal.PlainDate.from({
|
||||
year: 5779,
|
||||
month: 7,
|
||||
day: 1,
|
||||
calendar: "hebrew"
|
||||
});
|
||||
assert.sameValue(date.month, 7);
|
||||
assert.sameValue(date.monthCode, "M06");
|
||||
assert.sameValue(date.day, 1);
|
||||
date = Temporal.PlainDate.from({
|
||||
year: 5779,
|
||||
monthCode: "M06",
|
||||
day: 1,
|
||||
calendar: "hebrew"
|
||||
});
|
||||
assert.sameValue(date.month, 7);
|
||||
assert.sameValue(date.monthCode, "M06");
|
||||
assert.sameValue(date.day, 1);
|
||||
|
||||
// Invalid leap months: e.g. M02L
|
||||
for (var i = 1; i <= 12; i++) {
|
||||
if (i === 5)
|
||||
continue;
|
||||
assert.throws(RangeError, () => Temporal.PlainDate.from({
|
||||
year: 5779,
|
||||
monthCode: `M${ i.toString().padStart(2, "0") }L`,
|
||||
day: 1,
|
||||
calendar: "hebrew"
|
||||
}));
|
||||
}
|
||||
|
||||
// Leap month in non-leap year (reject): Adar I 5780
|
||||
assert.throws(RangeError, () => Temporal.PlainDate.from({
|
||||
year: 5780,
|
||||
monthCode: "M05L",
|
||||
day: 1,
|
||||
calendar: "hebrew"
|
||||
}, { overflow: "reject" }));
|
||||
|
||||
// Leap month in non-leap year (constrain): 15 Adar I 5780 => 30 Av 5780
|
||||
var date = Temporal.PlainDate.from({
|
||||
year: 5780,
|
||||
monthCode: "M05L",
|
||||
day: 15,
|
||||
calendar: "hebrew"
|
||||
});
|
||||
assert.sameValue(date.month, 5);
|
||||
assert.sameValue(date.monthCode, "M05");
|
||||
assert.sameValue(date.day, 30);
|
|
@ -0,0 +1,36 @@
|
|||
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal-intl
|
||||
description: Indian calendar
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
|
||||
// throws in Node 12 & 14 before 1 CE
|
||||
var vulnerableToBceBug = new Date("0000-01-01T00:00Z").toLocaleDateString("en-US-u-ca-indian", { timeZone: "UTC" }) !== "10/11/-79 Saka";
|
||||
if (vulnerableToBceBug) {
|
||||
assert.throws(RangeError, () => Temporal.PlainDate.from("0000-01-01").withCalendar("indian").day);
|
||||
}
|
||||
|
||||
// handles leap days
|
||||
var leapYearFirstDay = Temporal.PlainDate.from("2004-03-21[u-ca=indian]");
|
||||
assert.sameValue(leapYearFirstDay.year, 2004 - 78);
|
||||
assert.sameValue(leapYearFirstDay.month, 1);
|
||||
assert.sameValue(leapYearFirstDay.day, 1);
|
||||
var leapYearLastDay = leapYearFirstDay.with({ day: 31 });
|
||||
assert.sameValue(leapYearLastDay.year, 2004 - 78);
|
||||
assert.sameValue(leapYearLastDay.month, 1);
|
||||
assert.sameValue(leapYearLastDay.day, 31);
|
||||
|
||||
// handles non-leap years
|
||||
var nonLeapYearFirstDay = Temporal.PlainDate.from("2005-03-22[u-ca=indian]");
|
||||
assert.sameValue(nonLeapYearFirstDay.year, 2005 - 78);
|
||||
assert.sameValue(nonLeapYearFirstDay.month, 1);
|
||||
assert.sameValue(nonLeapYearFirstDay.day, 1);
|
||||
var leapYearLastDay = nonLeapYearFirstDay.with({ day: 31 });
|
||||
assert.sameValue(leapYearLastDay.year, 2005 - 78);
|
||||
assert.sameValue(leapYearLastDay.month, 1);
|
||||
assert.sameValue(leapYearLastDay.day, 30);
|
||||
assert.throws(RangeError, () => nonLeapYearFirstDay.with({ day: 31 }, { overflow: "reject" }));
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal-intl
|
||||
description: Instant.toLocaleString()
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
function maybeGetWeekdayOnlyFormat() {
|
||||
const fmt = new Intl.DateTimeFormat('en', { weekday: 'long', timeZone: 'Europe/Vienna' });
|
||||
if (
|
||||
['era', 'year', 'month', 'day', 'hour', 'minute', 'second', 'timeZoneName'].some(
|
||||
(prop) => prop in fmt.resolvedOptions()
|
||||
)
|
||||
) {
|
||||
//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")
|
||||
var fmt = maybeGetWeekdayOnlyFormat();
|
||||
if (fmt)
|
||||
assert.sameValue(fmt.format(instant), "Thursday");
|
||||
|
||||
// outputs timeZoneName if requested
|
||||
var str = instant.toLocaleString("en", {
|
||||
timeZone: "America/New_York",
|
||||
timeZoneName: "short"
|
||||
});
|
||||
assert(str.includes("EST"));
|
|
@ -0,0 +1,122 @@
|
|||
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal-intl
|
||||
description: Japanese eras
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
|
||||
// Reiwa (2019-)
|
||||
var date = Temporal.PlainDate.from({
|
||||
era: "reiwa",
|
||||
eraYear: 2,
|
||||
month: 1,
|
||||
day: 1,
|
||||
calendar: "japanese"
|
||||
});
|
||||
assert.sameValue(`${ date }`, "2020-01-01[u-ca=japanese]");
|
||||
|
||||
// Heisei (1989-2019)
|
||||
var date = Temporal.PlainDate.from({
|
||||
era: "heisei",
|
||||
eraYear: 2,
|
||||
month: 1,
|
||||
day: 1,
|
||||
calendar: "japanese"
|
||||
});
|
||||
assert.sameValue(`${ date }`, "1990-01-01[u-ca=japanese]");
|
||||
|
||||
// Showa (1926-1989)
|
||||
var date = Temporal.PlainDate.from({
|
||||
era: "showa",
|
||||
eraYear: 2,
|
||||
month: 1,
|
||||
day: 1,
|
||||
calendar: "japanese"
|
||||
});
|
||||
assert.sameValue(`${ date }`, "1927-01-01[u-ca=japanese]");
|
||||
|
||||
// Taisho (1912-1926)
|
||||
var date = Temporal.PlainDate.from({
|
||||
era: "taisho",
|
||||
eraYear: 2,
|
||||
month: 1,
|
||||
day: 1,
|
||||
calendar: "japanese"
|
||||
});
|
||||
assert.sameValue(`${ date }`, "1913-01-01[u-ca=japanese]");
|
||||
|
||||
// Meiji (1868-1912)
|
||||
var date = Temporal.PlainDate.from({
|
||||
era: "meiji",
|
||||
eraYear: 2,
|
||||
month: 1,
|
||||
day: 1,
|
||||
calendar: "japanese"
|
||||
});
|
||||
assert.sameValue(`${ date }`, "1869-01-01[u-ca=japanese]");
|
||||
|
||||
// Dates in same year before Japanese era starts will resolve to previous era
|
||||
var date = Temporal.PlainDate.from({
|
||||
era: "reiwa",
|
||||
eraYear: 1,
|
||||
month: 1,
|
||||
day: 1,
|
||||
calendar: "japanese"
|
||||
});
|
||||
assert.sameValue(`${ date }`, "2019-01-01[u-ca=japanese]");
|
||||
assert.sameValue(date.era, "heisei");
|
||||
assert.sameValue(date.eraYear, 31);
|
||||
date = Temporal.PlainDate.from({
|
||||
era: "heisei",
|
||||
eraYear: 1,
|
||||
month: 1,
|
||||
day: 1,
|
||||
calendar: "japanese"
|
||||
});
|
||||
assert.sameValue(`${ date }`, "1989-01-01[u-ca=japanese]");
|
||||
assert.sameValue(date.era, "showa");
|
||||
assert.sameValue(date.eraYear, 64);
|
||||
date = Temporal.PlainDate.from({
|
||||
era: "showa",
|
||||
eraYear: 1,
|
||||
month: 1,
|
||||
day: 1,
|
||||
calendar: "japanese"
|
||||
});
|
||||
assert.sameValue(`${ date }`, "1926-01-01[u-ca=japanese]");
|
||||
assert.sameValue(date.era, "taisho");
|
||||
assert.sameValue(date.eraYear, 15);
|
||||
date = Temporal.PlainDate.from({
|
||||
era: "taisho",
|
||||
eraYear: 1,
|
||||
month: 1,
|
||||
day: 1,
|
||||
calendar: "japanese"
|
||||
});
|
||||
assert.sameValue(`${ date }`, "1912-01-01[u-ca=japanese]");
|
||||
assert.sameValue(date.era, "meiji");
|
||||
assert.sameValue(date.eraYear, 45);
|
||||
date = Temporal.PlainDate.from({
|
||||
era: "meiji",
|
||||
eraYear: 1,
|
||||
month: 1,
|
||||
day: 1,
|
||||
calendar: "japanese"
|
||||
});
|
||||
assert.sameValue(`${ date }`, "1868-01-01[u-ca=japanese]");
|
||||
assert.sameValue(date.era, "ce");
|
||||
assert.sameValue(date.eraYear, 1868);
|
||||
assert.throws(RangeError, () => Temporal.PlainDate.from({
|
||||
era: "bce",
|
||||
eraYear: 1,
|
||||
month: 1,
|
||||
day: 1,
|
||||
calendar: "japanese"
|
||||
}));
|
||||
|
||||
// `with` doesn't crash when constraining dates out of bounds of the current era
|
||||
var date = Temporal.PlainDate.from("1989-01-07").withCalendar(Temporal.Calendar.from("japanese")).with({ day: 10 });
|
||||
assert.sameValue(`${ date }`, "1989-01-10[u-ca=japanese]");
|
|
@ -0,0 +1,43 @@
|
|||
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal-intl
|
||||
description: monthday.toLocaleString()
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var calendar = new Intl.DateTimeFormat("en").resolvedOptions().calendar;
|
||||
var monthday = Temporal.PlainMonthDay.from({
|
||||
monthCode: "M11",
|
||||
day: 18,
|
||||
calendar
|
||||
});
|
||||
assert.sameValue(`${ monthday.toLocaleString("en", { timeZone: "America/New_York" }) }`, "11/18")
|
||||
assert.sameValue(`${ monthday.toLocaleString("de", {
|
||||
timeZone: "Europe/Vienna",
|
||||
calendar
|
||||
}) }`, "18.11.")
|
||||
|
||||
// should ignore units not in the data type
|
||||
assert.sameValue(monthday.toLocaleString("en", { timeZoneName: "long" }), "11/18");
|
||||
assert.sameValue(monthday.toLocaleString("en", { year: "numeric" }), "11/18");
|
||||
assert.sameValue(monthday.toLocaleString("en", { hour: "numeric" }), "11/18");
|
||||
assert.sameValue(monthday.toLocaleString("en", { minute: "numeric" }), "11/18");
|
||||
assert.sameValue(monthday.toLocaleString("en", { second: "numeric" }), "11/18");
|
||||
assert.sameValue(monthday.toLocaleString("en", { weekday: "long" }), "11/18");
|
||||
|
||||
// works when the object's calendar is the same as the locale's calendar
|
||||
var md = Temporal.PlainMonthDay.from({
|
||||
monthCode: "M11",
|
||||
day: 18,
|
||||
calendar: "japanese"
|
||||
});
|
||||
assert.sameValue(`${ md.toLocaleString("en-US-u-ca-japanese") }`, "11/18");
|
||||
|
||||
// throws when the calendar is not equal to the locale calendar
|
||||
var mdISO = Temporal.PlainMonthDay.from({
|
||||
month: 11,
|
||||
day: 18
|
||||
});
|
||||
assert.throws(RangeError, () => mdISO.toLocaleString("en-US-u-ca-japanese"));
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,19 @@
|
|||
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal-zoneddatetime-objects
|
||||
description: time.toLocaleString()
|
||||
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")
|
||||
|
||||
// should ignore units not in the data type
|
||||
assert.sameValue(time.toLocaleString("en", { timeZoneName: "long" }), "3:23:30 PM");
|
||||
assert.sameValue(time.toLocaleString("en", { year: "numeric" }), "3:23:30 PM");
|
||||
assert.sameValue(time.toLocaleString("en", { month: "numeric" }), "3:23:30 PM");
|
||||
assert.sameValue(time.toLocaleString("en", { day: "numeric" }), "3:23:30 PM");
|
||||
assert.sameValue(time.toLocaleString("en", { weekday: "long" }), "3:23:30 PM");
|
|
@ -0,0 +1,46 @@
|
|||
|
||||
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal-intl
|
||||
description: yearmonth.toLocaleString()
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
var calendar = new Intl.DateTimeFormat("en").resolvedOptions().calendar;
|
||||
var yearmonth = Temporal.PlainYearMonth.from({
|
||||
year: 1976,
|
||||
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")
|
||||
|
||||
// should ignore units not in the data type
|
||||
assert.sameValue(yearmonth.toLocaleString("en", { timeZoneName: "long" }), "11/1976");
|
||||
assert.sameValue(yearmonth.toLocaleString("en", { day: "numeric" }), "11/1976");
|
||||
assert.sameValue(yearmonth.toLocaleString("en", { hour: "numeric" }), "11/1976");
|
||||
assert.sameValue(yearmonth.toLocaleString("en", { minute: "numeric" }), "11/1976");
|
||||
assert.sameValue(yearmonth.toLocaleString("en", { second: "numeric" }), "11/1976");
|
||||
assert.sameValue(yearmonth.toLocaleString("en", { weekday: "long" }), "11/1976");
|
||||
|
||||
// works when the object's calendar is the same as the locale's calendar
|
||||
var ym = Temporal.PlainYearMonth.from({
|
||||
era: "showa",
|
||||
eraYear: 51,
|
||||
month: 11,
|
||||
calendar: "japanese"
|
||||
});
|
||||
var result = ym.toLocaleString("en-US-u-ca-japanese");
|
||||
assert(result === "11/51" || result === "11/51 S");
|
||||
|
||||
// throws when the calendar is not equal to the locale calendar
|
||||
var ymISO = Temporal.PlainYearMonth.from({
|
||||
year: 1976,
|
||||
month: 11
|
||||
});
|
||||
assert.throws(RangeError, () => ymISO.toLocaleString("en-US-u-ca-japanese"));
|
|
@ -0,0 +1,51 @@
|
|||
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal-zoneddatetime-objects
|
||||
description: zoneddatetime.toLocaleString()
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
function maybeGetWeekdayOnlyFormat() {
|
||||
const fmt = new Intl.DateTimeFormat('en', { weekday: 'long', timeZone: 'Europe/Vienna' });
|
||||
if (
|
||||
['era', 'year', 'month', 'day', 'hour', 'minute', 'second', 'timeZoneName'].some(
|
||||
(prop) => prop in fmt.resolvedOptions()
|
||||
)
|
||||
) {
|
||||
//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")
|
||||
|
||||
const fmt = maybeGetWeekdayOnlyFormat();
|
||||
//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");
|
||||
|
||||
// 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");
|
||||
|
||||
// throws if the time zone given in options disagrees with the object's time zone
|
||||
assert.throws(RangeError, () => zdt.toLocaleString("en", { timeZone: "America/New_York" }));
|
||||
|
||||
// works when the object's calendar is the same as the locale's calendar
|
||||
var zdt = new Temporal.ZonedDateTime(0n, "UTC", "japanese");
|
||||
var result = zdt.toLocaleString("en-US-u-ca-japanese");
|
||||
assert(result === "1/1/45, 12:00:00 AM UTC" || result === "1/1/45 S, 12:00:00 AM UTC");
|
||||
|
||||
// adopts the locale's calendar when the object's calendar is ISO
|
||||
var zdt = Temporal.ZonedDateTime.from("1976-11-18T15:23:30+00:00[UTC]");
|
||||
var result = zdt.toLocaleString("en-US-u-ca-japanese");
|
||||
assert(result === "11/18/51, 3:23:30 PM UTC" || result === "11/18/51 S, 3:23:30 PM UTC");
|
||||
|
||||
// throws when the calendars are different and not ISO
|
||||
var zdt = new Temporal.ZonedDateTime(0n, "UTC", "gregory");
|
||||
assert.throws(RangeError, () => zdt.toLocaleString("en-US-u-ca-japanese"));
|
Loading…
Reference in New Issue