Skip to content

Commit 88f31d7

Browse files
authored
Add more options to DateTimeFormatOptions.timeZoneName (#48467)
* update timeZoneName * add tests and baselines
1 parent 312737b commit 88f31d7

File tree

5 files changed

+94
-1
lines changed

5 files changed

+94
-1
lines changed

src/lib/es5.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4404,7 +4404,7 @@ declare namespace Intl {
44044404
hour?: "numeric" | "2-digit" | undefined;
44054405
minute?: "numeric" | "2-digit" | undefined;
44064406
second?: "numeric" | "2-digit" | undefined;
4407-
timeZoneName?: "long" | "short" | undefined;
4407+
timeZoneName?: "short" | "long" | "shortOffset" | "longOffset" | "shortGeneric" | "longGeneric" | undefined;
44084408
formatMatcher?: "best fit" | "basic" | undefined;
44094409
hour12?: boolean | undefined;
44104410
timeZone?: string | undefined;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [es2022IntlAPIs.ts]
2+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#using_timezonename
3+
const timezoneNames = ['short', 'long', 'shortOffset', 'longOffset', 'shortGeneric', 'longGeneric'] as const;
4+
for (const zoneName of timezoneNames) {
5+
var formatter = new Intl.DateTimeFormat('en-US', {
6+
timeZone: 'America/Los_Angeles',
7+
timeZoneName: zoneName,
8+
});
9+
}
10+
11+
12+
//// [es2022IntlAPIs.js]
13+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#using_timezonename
14+
const timezoneNames = ['short', 'long', 'shortOffset', 'longOffset', 'shortGeneric', 'longGeneric'];
15+
for (const zoneName of timezoneNames) {
16+
var formatter = new Intl.DateTimeFormat('en-US', {
17+
timeZone: 'America/Los_Angeles',
18+
timeZoneName: zoneName,
19+
});
20+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
=== tests/cases/conformance/es2022/es2022IntlAPIs.ts ===
2+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#using_timezonename
3+
const timezoneNames = ['short', 'long', 'shortOffset', 'longOffset', 'shortGeneric', 'longGeneric'] as const;
4+
>timezoneNames : Symbol(timezoneNames, Decl(es2022IntlAPIs.ts, 1, 5))
5+
>const : Symbol(const)
6+
7+
for (const zoneName of timezoneNames) {
8+
>zoneName : Symbol(zoneName, Decl(es2022IntlAPIs.ts, 2, 10))
9+
>timezoneNames : Symbol(timezoneNames, Decl(es2022IntlAPIs.ts, 1, 5))
10+
11+
var formatter = new Intl.DateTimeFormat('en-US', {
12+
>formatter : Symbol(formatter, Decl(es2022IntlAPIs.ts, 3, 5))
13+
>Intl.DateTimeFormat : Symbol(Intl.DateTimeFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2021.intl.d.ts, --, --))
14+
>Intl : Symbol(Intl, Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2018.intl.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.intl.d.ts, --, --) ... and 1 more)
15+
>DateTimeFormat : Symbol(Intl.DateTimeFormat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2017.intl.d.ts, --, --), Decl(lib.es2021.intl.d.ts, --, --))
16+
17+
timeZone: 'America/Los_Angeles',
18+
>timeZone : Symbol(timeZone, Decl(es2022IntlAPIs.ts, 3, 52))
19+
20+
timeZoneName: zoneName,
21+
>timeZoneName : Symbol(timeZoneName, Decl(es2022IntlAPIs.ts, 4, 36))
22+
>zoneName : Symbol(zoneName, Decl(es2022IntlAPIs.ts, 2, 10))
23+
24+
});
25+
}
26+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
=== tests/cases/conformance/es2022/es2022IntlAPIs.ts ===
2+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#using_timezonename
3+
const timezoneNames = ['short', 'long', 'shortOffset', 'longOffset', 'shortGeneric', 'longGeneric'] as const;
4+
>timezoneNames : readonly ["short", "long", "shortOffset", "longOffset", "shortGeneric", "longGeneric"]
5+
>['short', 'long', 'shortOffset', 'longOffset', 'shortGeneric', 'longGeneric'] as const : readonly ["short", "long", "shortOffset", "longOffset", "shortGeneric", "longGeneric"]
6+
>['short', 'long', 'shortOffset', 'longOffset', 'shortGeneric', 'longGeneric'] : readonly ["short", "long", "shortOffset", "longOffset", "shortGeneric", "longGeneric"]
7+
>'short' : "short"
8+
>'long' : "long"
9+
>'shortOffset' : "shortOffset"
10+
>'longOffset' : "longOffset"
11+
>'shortGeneric' : "shortGeneric"
12+
>'longGeneric' : "longGeneric"
13+
14+
for (const zoneName of timezoneNames) {
15+
>zoneName : "short" | "long" | "shortOffset" | "longOffset" | "shortGeneric" | "longGeneric"
16+
>timezoneNames : readonly ["short", "long", "shortOffset", "longOffset", "shortGeneric", "longGeneric"]
17+
18+
var formatter = new Intl.DateTimeFormat('en-US', {
19+
>formatter : Intl.DateTimeFormat
20+
>new Intl.DateTimeFormat('en-US', { timeZone: 'America/Los_Angeles', timeZoneName: zoneName, }) : Intl.DateTimeFormat
21+
>Intl.DateTimeFormat : { (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; new (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; supportedLocalesOf(locales: string | string[], options?: Intl.DateTimeFormatOptions): string[]; readonly prototype: Intl.DateTimeFormat; }
22+
>Intl : typeof Intl
23+
>DateTimeFormat : { (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; new (locales?: string | string[], options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat; supportedLocalesOf(locales: string | string[], options?: Intl.DateTimeFormatOptions): string[]; readonly prototype: Intl.DateTimeFormat; }
24+
>'en-US' : "en-US"
25+
>{ timeZone: 'America/Los_Angeles', timeZoneName: zoneName, } : { timeZone: string; timeZoneName: "short" | "long" | "shortOffset" | "longOffset" | "shortGeneric" | "longGeneric"; }
26+
27+
timeZone: 'America/Los_Angeles',
28+
>timeZone : string
29+
>'America/Los_Angeles' : "America/Los_Angeles"
30+
31+
timeZoneName: zoneName,
32+
>timeZoneName : "short" | "long" | "shortOffset" | "longOffset" | "shortGeneric" | "longGeneric"
33+
>zoneName : "short" | "long" | "shortOffset" | "longOffset" | "shortGeneric" | "longGeneric"
34+
35+
});
36+
}
37+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @target: es2022
2+
3+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#using_timezonename
4+
const timezoneNames = ['short', 'long', 'shortOffset', 'longOffset', 'shortGeneric', 'longGeneric'] as const;
5+
for (const zoneName of timezoneNames) {
6+
var formatter = new Intl.DateTimeFormat('en-US', {
7+
timeZone: 'America/Los_Angeles',
8+
timeZoneName: zoneName,
9+
});
10+
}

0 commit comments

Comments
 (0)