1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
// 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-US", { timeZone: "America/New_York" }) }`, "11/18/1976");
assert.sameValue(`${ date.toLocaleString("de-AT", { 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-US", { timeZoneName: "long" }), "11/18/1976");
assert.sameValue(date.toLocaleString("en-US", { hour: "numeric" }), "11/18/1976");
assert.sameValue(date.toLocaleString("en-US", { minute: "numeric" }), "11/18/1976");
assert.sameValue(date.toLocaleString("en-US", { second: "numeric" }), "11/18/1976");
reportCompare(0, 0);
|