From 9079a43e030e9ba1802cafda66472a17214a9fa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Sundstr=C3=B6m?= Date: Tue, 12 May 2020 20:17:08 -0700 Subject: [PATCH 1/2] fix: fixes #35865 - document and flesh out legal Intl.DateTimeFormatOptions types --- lib/lib.es5.d.ts | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/lib/lib.es5.d.ts b/lib/lib.es5.d.ts index ec5e1a5723ced..267b09102e341 100644 --- a/lib/lib.es5.d.ts +++ b/lib/lib.es5.d.ts @@ -4297,20 +4297,34 @@ declare namespace Intl { supportedLocalesOf(locales: string | string[], options?: NumberFormatOptions): string[]; }; + type DateFormatNumericVerbosity = "numeric" | "2-digit"; + type DateFormatNameVerbosity = "long" | "short" | "narrow"; + interface DateTimeFormatOptions { - localeMatcher?: string; - weekday?: string; - era?: string; - year?: string; - month?: string; - day?: string; - hour?: string; - minute?: string; - second?: string; - timeZoneName?: string; - formatMatcher?: string; + /** output examples – numeric: "2020", 2-digit: "20" */ + year?: DateFormatNumericVerbosity; + /** output examples – numeric: "3", 2-digit: "03", long: "March", short: "Mar", narrow: "M" */ + month?: DateFormatNumericVerbosity | DateFormatNameVerbosity; + /** output examples – numeric: "2", 2-digit: "02" */ + day?: DateFormatNumericVerbosity; + /** output examples – numeric: "2", 2-digit: "02" */ + hour?: DateFormatNumericVerbosity; + /** output examples – numeric: "2", 2-digit: "02" */ + minute?: DateFormatNumericVerbosity; + /** output examples – numeric: "2", 2-digit: "02" */ + second?: DateFormatNumericVerbosity; + /** output examples – long: "Thursday", short: "Thu", narrow: "T" */ + weekday?: DateFormatNameVerbosity; + /** output examples – long: "Anno Domini", short: "AD", narrow "A" */ + era?: DateFormatNameVerbosity; + /** set to `true` to force 12-hour am/pm "dayPeriod" values, or `false` to force 24-hour time without */ hour12?: boolean; + /** output examples – long: "Pacific Daylight Time", short: "PDT" */ + timeZoneName?: "long" | "short"; + /** set to the timezone name you want to render date and time for, e g "UTC", "Europe/Rome" */ timeZone?: string; + localeMatcher?: "best fit" | "lookup"; + formatMatcher?: "best fit" | "basic"; } interface ResolvedDateTimeFormatOptions { From bbbd8d2aeae2c96c9405bb4e4c472ff264ea1493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Sundstr=C3=B6m?= Date: Tue, 12 May 2020 20:24:58 -0700 Subject: [PATCH 2/2] test: update tests --- tests/lib/lib.d.ts | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/tests/lib/lib.d.ts b/tests/lib/lib.d.ts index 9edbdec2b1b13..4faa6e6d2d117 100644 --- a/tests/lib/lib.d.ts +++ b/tests/lib/lib.d.ts @@ -3927,20 +3927,34 @@ declare module Intl { supportedLocalesOf(locale: string, options?: NumberFormatOptions): string[]; } + type DateFormatNumericVerbosity = "numeric" | "2-digit"; + type DateFormatNameVerbosity = "long" | "short" | "narrow"; + interface DateTimeFormatOptions { - localeMatcher?: string; - weekday?: string; - era?: string; - year?: string; - month?: string; - day?: string; - hour?: string; - minute?: string; - second?: string; - timeZoneName?: string; - formatMatcher?: string; + /** output examples – numeric: "2020", 2-digit: "20" */ + year?: DateFormatNumericVerbosity; + /** output examples – numeric: "3", 2-digit: "03", long: "March", short: "Mar", narrow: "M" */ + month?: DateFormatNumericVerbosity | DateFormatNameVerbosity; + /** output examples – numeric: "2", 2-digit: "02" */ + day?: DateFormatNumericVerbosity; + /** output examples – numeric: "2", 2-digit: "02" */ + hour?: DateFormatNumericVerbosity; + /** output examples – numeric: "2", 2-digit: "02" */ + minute?: DateFormatNumericVerbosity; + /** output examples – numeric: "2", 2-digit: "02" */ + second?: DateFormatNumericVerbosity; + /** output examples – long: "Thursday", short: "Thu", narrow: "T" */ + weekday?: DateFormatNameVerbosity; + /** output examples – long: "Anno Domini", short: "AD", narrow "A" */ + era?: DateFormatNameVerbosity; + /** set to `true` to force 12-hour am/pm "dayPeriod" values, or `false` to force 24-hour time without */ hour12?: boolean; + /** output examples – long: "Pacific Daylight Time", short: "PDT" */ + timeZoneName?: "long" | "short"; + /** set to the timezone name you want to render date and time for, e g "UTC", "Europe/Rome" */ timeZone?: string; + localeMatcher?: "best fit" | "lookup"; + formatMatcher?: "best fit" | "basic"; } interface ResolvedDateTimeFormatOptions {