Skip to content

Commit d2948a2

Browse files
add DTF date-time components
1 parent ca18fa9 commit d2948a2

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

js/region.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ const set_oIntlTests = () => new Promise(resolve => {
262262
curS = {"symbol": [1000]},
263263
curB = {"name": [-1], "symbol": [1000]},
264264
curA = {"accounting": [-1000], "name": [-1], "symbol": [1000]}
265+
let dateA = new Date("January 18, 2023 1:00:00"),
266+
dateB = new Date("January 20, 2023 13:00:00")
265267

266268
oIntlTests = {
267269
"collation": [
@@ -281,6 +283,30 @@ const set_oIntlTests = () => new Promise(resolve => {
281283
"narrow": ["conjunction","disjunction","unit"],
282284
"short": ["conjunction","unit"]
283285
},
286+
"datetimeformat": {
287+
"era": {
288+
// we need to control the date part so toLocaleString matches
289+
"long": [{era: "long", year: "numeric", month: "numeric", day: "numeric"}, [new Date("-000001")]]
290+
},
291+
"fractionalSecondDigits": {
292+
"1": [{minute: "numeric", second: 'numeric', fractionalSecondDigits: 1}, [new Date("2022-06-11T01:12:34.5678Z")]]
293+
},
294+
"hour": {
295+
"numeric": [{hour: "numeric"}, [dateA]],
296+
},
297+
"hourCycle": {
298+
"h11-2-digit": [{hour: "2-digit", hourCycle: "h11"}, [dateA]]
299+
},
300+
"month": {
301+
"narrow": [{month: "narrow"}, [new Date("2023-11-15")] ],
302+
"short": [{month: "short"}, [new Date("2023-01-15"), new Date("2023-09-15")]],
303+
},
304+
"weekday": {
305+
"long": [{weekday: "long"}, [dateA, dateB]],
306+
"narrow": [{weekday: "narrow"}, [dateA, dateB]],
307+
"short": [{weekday: "short"}, [dateB]],
308+
},
309+
},
284310
"notation": {
285311
"scientific": {"decimal": []},
286312
"standard": {"decimal": [0/0, -1000, 987654], "percent": [1000]},
@@ -534,6 +560,18 @@ const get_locale_intl = () => new Promise(resolve => {
534560
obj[key][s] = data
535561
})
536562
})
563+
} else if (m == "datetimeformat") {
564+
Object.keys(tests).forEach(function(key) {
565+
obj[key] = {}
566+
Object.keys(tests[key]).forEach(function(s) {
567+
let option = tests[key][s][0]
568+
let formatter = new Intl.DateTimeFormat(code, option), data = []
569+
tests[key][s][1].forEach(function(n){
570+
value = (isIntl ? formatter.format(n) : (n).toLocaleString(code, option)); data.push(value)
571+
})
572+
obj[key][s] = data
573+
})
574+
})
537575
} else if (m == "dayperiod") {
538576
Object.keys(tests).forEach(function(key) {
539577
let formatter = new Intl.DateTimeFormat(code, {hourCycle: "h12", dayPeriod: key}), data = []
@@ -660,10 +698,10 @@ const get_locale_intl = () => new Promise(resolve => {
660698
}
661699
const oMetrics = {
662700
"intl" : [
663-
"collation","compact", "currency", "dayperiod", "listformat","notation","numberformat_ftp",
701+
"collation","compact", "currency", "datetimeformat","dayperiod", "listformat","notation","numberformat_ftp",
664702
"pluralrules","relativetimeformat","relativetimeformat_ftp","sign","timezonename","unit"
665703
],
666-
"tolocalestring": ["compact","currency","notation","sign","timezonename","unit"],
704+
"tolocalestring": ["compact","currency","datetimeformat","notation","sign","timezonename","unit"],
667705
}
668706
let t0 = nowFn(), notation = ""
669707
let METRIC, oString = {}

0 commit comments

Comments
 (0)