mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Add more options to DateTimeFormatOptions.timeZoneName (#48467)
* update timeZoneName * add tests and baselines
This commit is contained in:
Vendored
+1
-1
@@ -4404,7 +4404,7 @@ declare namespace Intl {
|
||||
hour?: "numeric" | "2-digit" | undefined;
|
||||
minute?: "numeric" | "2-digit" | undefined;
|
||||
second?: "numeric" | "2-digit" | undefined;
|
||||
timeZoneName?: "long" | "short" | undefined;
|
||||
timeZoneName?: "short" | "long" | "shortOffset" | "longOffset" | "shortGeneric" | "longGeneric" | undefined;
|
||||
formatMatcher?: "best fit" | "basic" | undefined;
|
||||
hour12?: boolean | undefined;
|
||||
timeZone?: string | undefined;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
//// [es2022IntlAPIs.ts]
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#using_timezonename
|
||||
const timezoneNames = ['short', 'long', 'shortOffset', 'longOffset', 'shortGeneric', 'longGeneric'] as const;
|
||||
for (const zoneName of timezoneNames) {
|
||||
var formatter = new Intl.DateTimeFormat('en-US', {
|
||||
timeZone: 'America/Los_Angeles',
|
||||
timeZoneName: zoneName,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//// [es2022IntlAPIs.js]
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#using_timezonename
|
||||
const timezoneNames = ['short', 'long', 'shortOffset', 'longOffset', 'shortGeneric', 'longGeneric'];
|
||||
for (const zoneName of timezoneNames) {
|
||||
var formatter = new Intl.DateTimeFormat('en-US', {
|
||||
timeZone: 'America/Los_Angeles',
|
||||
timeZoneName: zoneName,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
=== tests/cases/conformance/es2022/es2022IntlAPIs.ts ===
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#using_timezonename
|
||||
const timezoneNames = ['short', 'long', 'shortOffset', 'longOffset', 'shortGeneric', 'longGeneric'] as const;
|
||||
>timezoneNames : Symbol(timezoneNames, Decl(es2022IntlAPIs.ts, 1, 5))
|
||||
>const : Symbol(const)
|
||||
|
||||
for (const zoneName of timezoneNames) {
|
||||
>zoneName : Symbol(zoneName, Decl(es2022IntlAPIs.ts, 2, 10))
|
||||
>timezoneNames : Symbol(timezoneNames, Decl(es2022IntlAPIs.ts, 1, 5))
|
||||
|
||||
var formatter = new Intl.DateTimeFormat('en-US', {
|
||||
>formatter : Symbol(formatter, Decl(es2022IntlAPIs.ts, 3, 5))
|
||||
>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, --, --))
|
||||
>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)
|
||||
>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, --, --))
|
||||
|
||||
timeZone: 'America/Los_Angeles',
|
||||
>timeZone : Symbol(timeZone, Decl(es2022IntlAPIs.ts, 3, 52))
|
||||
|
||||
timeZoneName: zoneName,
|
||||
>timeZoneName : Symbol(timeZoneName, Decl(es2022IntlAPIs.ts, 4, 36))
|
||||
>zoneName : Symbol(zoneName, Decl(es2022IntlAPIs.ts, 2, 10))
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
=== tests/cases/conformance/es2022/es2022IntlAPIs.ts ===
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#using_timezonename
|
||||
const timezoneNames = ['short', 'long', 'shortOffset', 'longOffset', 'shortGeneric', 'longGeneric'] as const;
|
||||
>timezoneNames : readonly ["short", "long", "shortOffset", "longOffset", "shortGeneric", "longGeneric"]
|
||||
>['short', 'long', 'shortOffset', 'longOffset', 'shortGeneric', 'longGeneric'] as const : readonly ["short", "long", "shortOffset", "longOffset", "shortGeneric", "longGeneric"]
|
||||
>['short', 'long', 'shortOffset', 'longOffset', 'shortGeneric', 'longGeneric'] : readonly ["short", "long", "shortOffset", "longOffset", "shortGeneric", "longGeneric"]
|
||||
>'short' : "short"
|
||||
>'long' : "long"
|
||||
>'shortOffset' : "shortOffset"
|
||||
>'longOffset' : "longOffset"
|
||||
>'shortGeneric' : "shortGeneric"
|
||||
>'longGeneric' : "longGeneric"
|
||||
|
||||
for (const zoneName of timezoneNames) {
|
||||
>zoneName : "short" | "long" | "shortOffset" | "longOffset" | "shortGeneric" | "longGeneric"
|
||||
>timezoneNames : readonly ["short", "long", "shortOffset", "longOffset", "shortGeneric", "longGeneric"]
|
||||
|
||||
var formatter = new Intl.DateTimeFormat('en-US', {
|
||||
>formatter : Intl.DateTimeFormat
|
||||
>new Intl.DateTimeFormat('en-US', { timeZone: 'America/Los_Angeles', timeZoneName: zoneName, }) : Intl.DateTimeFormat
|
||||
>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; }
|
||||
>Intl : typeof 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; }
|
||||
>'en-US' : "en-US"
|
||||
>{ timeZone: 'America/Los_Angeles', timeZoneName: zoneName, } : { timeZone: string; timeZoneName: "short" | "long" | "shortOffset" | "longOffset" | "shortGeneric" | "longGeneric"; }
|
||||
|
||||
timeZone: 'America/Los_Angeles',
|
||||
>timeZone : string
|
||||
>'America/Los_Angeles' : "America/Los_Angeles"
|
||||
|
||||
timeZoneName: zoneName,
|
||||
>timeZoneName : "short" | "long" | "shortOffset" | "longOffset" | "shortGeneric" | "longGeneric"
|
||||
>zoneName : "short" | "long" | "shortOffset" | "longOffset" | "shortGeneric" | "longGeneric"
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// @target: es2022
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#using_timezonename
|
||||
const timezoneNames = ['short', 'long', 'shortOffset', 'longOffset', 'shortGeneric', 'longGeneric'] as const;
|
||||
for (const zoneName of timezoneNames) {
|
||||
var formatter = new Intl.DateTimeFormat('en-US', {
|
||||
timeZone: 'America/Los_Angeles',
|
||||
timeZoneName: zoneName,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user