Skip to content

Commit

Permalink
ICU76 (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorin-Oakenpants authored Nov 2, 2024
1 parent 80815d2 commit dfdafda
Show file tree
Hide file tree
Showing 16 changed files with 339 additions and 417 deletions.
82 changes: 44 additions & 38 deletions js/region.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ function set_oIntlTests() {
FSD: new Date('2023-06-11T01:12:34.5678'), // no Z
Era: new Date(-1, -11, -30),
Jan: new Date('2023-01-15'),
Jun: new Date("2023-06-15"),
Sep: new Date('2023-09-15'),
Nov: new Date('2023-11-15'),
Wed: new Date('January 18, 2023 1:00:00'), // doubles as hour 1
Expand All @@ -243,7 +244,7 @@ function set_oIntlTests() {
},
compact: {
'long': [0/0, 1000, 2e6, 6.6e12, 7e15],
'short': [-1100000000],
'short': [-1100000000, -1000],
},
currency: {'KES': curB, 'MOP': curS, 'USD': curA, 'XXX': curN,},
dayperiod: {'long': [8,22], 'narrow': [8,15], 'short': [12,15,18]},
Expand All @@ -263,7 +264,7 @@ function set_oIntlTests() {
},
month: {
'narrow': [{month: 'narrow'}, [dates.Nov] ],
'short': [{month: 'short'}, [dates.Jan, dates.Sep]],
'short': [{month: 'short'}, [dates.Jan, dates.Jun, dates.Sep]],
},
weekday: {
'long': [{weekday: 'long'}, [dates.Wed, dates.Fri]],
Expand Down Expand Up @@ -749,46 +750,51 @@ function get_locale_intl() {
}

function get_locale_resolvedoptions(METRIC) {

function get_metric(m, code) {
let r
let type = 'string'
try {
// collator
if (m == 'caseFirst') {r = Intl.Collator(code).resolvedOptions().caseFirst
} else if (m == 'ignorePunctuation') {type = 'boolean'; r = Intl.Collator(code).resolvedOptions().ignorePunctuation
// DTF
} else if (m == 'calendar') {r = Intl.DateTimeFormat(code).resolvedOptions().calendar
} else if (m == 'day') {r = Intl.DateTimeFormat(code).resolvedOptions().day
} else if (m == 'hourCycle') {r = Intl.DateTimeFormat(code, {hour: 'numeric'}).resolvedOptions().hourCycle
} else if (m == 'month') {r = Intl.DateTimeFormat(code).resolvedOptions().month
} else if (m == 'numberingSystem_dtf') {r = Intl.DateTimeFormat(code).resolvedOptions().numberingSystem
// NF
} else if (m == 'numberingSystem_nf') {r = new Intl.NumberFormat(code).resolvedOptions().numberingSystem
// PR
} else if (m == 'pluralCategories') {r = new Intl.PluralRules(code).resolvedOptions().pluralCategories.join(', ')
// RTF
} else if (m == 'numberingSystem_rtf') {r = new Intl.RelativeTimeFormat(code).resolvedOptions().numberingSystem
// already sorted
let oTests = {
collator: ['caseFirst'],
datetimeformat: ['calendar','day','hourcycle','month','numberingSystem'],
pluralrules: ['pluralCategories'],
}
function get_metrics(code) {
let tmpData = {}
for (const k of Object.keys(oTests)) {
tmpData[k] = {}
let metrics = oTests[k]
try {
// set constructor
let constructor
if ('collator' == k) {constructor = Intl.Collator(code).resolvedOptions()
} else if ('datetimeformat' == k) {constructor = Intl.DateTimeFormat(code).resolvedOptions()
} else if ('pluralrules' == k) {constructor = new Intl.PluralRules(code).resolvedOptions()
}
// get values
metrics.forEach(function(m) {
try {
let value
if ('hourcycle' == m) {
value = Intl.DateTimeFormat(code, {hour: "numeric"}).resolvedOptions().hourCycle
} else if ('pluralCategories' == m) {
value = constructor[m].join(', ')
} else {
value = constructor[m]
}
tmpData[k][m] = value
} catch(e) {
log_error(4, METRIC +'_'+ k + '_'+ m, e)
tmpData[k][m] = zErr
}
})
} catch(e) {
log_error(4, METRIC +'_'+ k, e)
tmpData[k] = zErr
}
if (runST) {r = undefined}
let typeCheck = typeFn(r)
if (type !== typeCheck) {throw zErrType + typeCheck}
return r
} catch(e) {
log_error(4, METRIC +'_'+ m, e)
return zErr
}
return tmpData
}

let oData = {}, oCheck = {}, notation = locale_red
let metrics = [
'calendar','caseFirst','day','hourCycle','ignorePunctuation','month',
'numberingSystem_dtf','numberingSystem_nf','numberingSystem_rtf','pluralCategories',
]
metrics.forEach(function(m) {oData[m] = get_metric(m, undefined)})
if (isLocaleValid) {
metrics.forEach(function(m) {oCheck[m] = get_metric(m, isLocaleValue)})
}
let oData = get_metrics(undefined), oCheck = {}, notation = locale_red
if (isLocaleValid) {oCheck = get_metrics(isLocaleValue)}
let hash = mini(oData), btnDiff = ''
if (isLocaleValid) {
if (hash == mini(oCheck)) {
Expand Down
14 changes: 6 additions & 8 deletions tests/collation.html
Original file line number Diff line number Diff line change
Expand Up @@ -523,16 +523,13 @@
let ff = ""
// don't notate unless it's our own preset
if (isFF && thisHash == exampleHash) {
// only hash notate if 102+
let is102 = (CanvasRenderingContext2D.prototype.hasOwnProperty("direction") && Array(1).includes())
if (is102) {
if (localesHash == "a7d80e7c") {ff = "110+"
} else if (localesHash == "ec4e8131") {ff = "102-109"
} else {ff = zNEW}
if (ff !== zNEW) {ff = s14 +"[FF"+ ff + "]"+ sc}
// notate new if 128+
if (isVer > 127) {
if (localesHash == "a7d80e7c") { // FF128+
} else {localesHash += ' '+ zNEW}
}
}
strItem = s12 +"locales: "+ sc + localesHash +" "+ ff +"<br>"
strItem = s12 +"locales: "+ sc + localesHash +"<br>"
output.push(strItem)

// details
Expand All @@ -554,6 +551,7 @@
Promise.all([
get_globals()
]).then(function(){
get_isVer()
// add additional locales to core locales for this test
let aListExtra = [
"bs-cyrl,bosnian (cyrillic)",
Expand Down
36 changes: 20 additions & 16 deletions tests/dtf.html
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,13 @@
],
"month": [
[new Date("2023-01-15"), {"short": {month: "short"}}],
[new Date("2023-06-15"), {"short": {month: "short"}}],
[new Date("2023-09-15"), {"short": {month: "short"}}],
[new Date("2023-11-15"), {"narrow": {month: "narrow"}}],
],
"weekday": [
[dateA, {"narrow": {weekday: "narrow"}, "long": {weekday: "long"}}],
[dateB, {"short": {weekday: "short"}, "narrow": {weekday: "narrow"}, "long": {weekday: "long"}}]
[dateB, {"short": {weekday: "short"}, "narrow": {weekday: "narrow"}, "long": {weekday: "long"}}],
],
}

Expand Down Expand Up @@ -278,6 +279,7 @@
try {oConst.WeL = new Intl.DateTimeFormat(code, {weekday: "long"})} catch(e) {}
try {oConst.MoS = new Intl.DateTimeFormat(code, {month: "short"})} catch(e) {}
try {oConst.MoN = new Intl.DateTimeFormat(code, {month: "narrow"})} catch(e) {}
//try {oConst.MoL = new Intl.DateTimeFormat(code, {month: "long"})} catch(e) {}
try {oConst.HoN = new Intl.DateTimeFormat(code, {hour: "numeric"})} catch(e) {}
try {oConst.HoH = new Intl.DateTimeFormat(code, {hour: "2-digit", hourCycle: "h11"})} catch(e) {}
try {oConst.ErL = new Intl.DateTimeFormat(code, {era: "long"})} catch(e) {}
Expand Down Expand Up @@ -361,21 +363,18 @@
let localesMatch = ""
if (method == "all") {
localesHashAll = localesHash
if (isFF) {
// only hash notate if 115+
let is115 = (CanvasRenderingContext2D.prototype.hasOwnProperty("letterSpacing"))
if (is115) {
// track FF version changes
// ignore if non-supported used, which return same as undefined = user's resolved options
// results
if (resultsHash == "80c3fd6b") {resultsHash += s14 +" [FF127+]"+ sc
} else if (resultsHash == "72c1b3f5") {resultsHash += s14 +" [FF115-126]"+ sc
} else {resultsHash += ' '+ zNEW
}
// locales
if (localesHash == "86c0f15f") {localesHash += s14 +" [FF115+]"+ sc
} else {localesHash += ' '+ zNEW
}
// notate new if 128+
if (isVer > 127) {
// ignore if non-supported used, which return same as undefined = user's resolved options
// results
if (resultsHash == "b33bb78b") { // FF134+
} else if (resultsHash == "0095da8a") { // FF128-133
} else {resultsHash += ' '+ zNEW
}
// locales
if (localesHash == "eef79c58") { // FF134+: 310
} else if (localesHash == "0c9d407a") { // FF128-133: 301
} else {localesHash += ' '+ zNEW
}
}
} else if (method == "min") {
Expand Down Expand Up @@ -422,6 +421,7 @@
Promise.all([
get_globals()
]).then(function(){
get_isVer()
try {
// pointless if we can't use the feature being tested: FF58+
let test = new Intl.DateTimeFormat("en").formatToParts(new Date)
Expand Down Expand Up @@ -457,13 +457,16 @@
"en-ca,english (canada)",
"en-ch,english (switzerland)",
"en-dk,english (denmark)",
"en-gb,english (united kingdom)",
"en-ie,english (ireland)",
"en-il,english (israel)",
"es-419,spanish (latin america and the caribbean)",
"es-ar,spanish (argentina)",
"es-bz,spanish (belize)",
"es-cl,spanish (chile)",
"es-co,spanish (colombia)",
"es-do,spanish (dominican republic)",
"es-mx,spanish (mexico)",
"es-pe,spanish (peru)",
"es-ph,spanish (philippines)",
"es-uy,spanish (uruguay)",
Expand All @@ -480,6 +483,7 @@
"hi-latn,hindi (latin)",
"hr-ba,croatian (bosnia & herzegovina)",
"it-ch,italian (switzerland)",
"kok-latn,konkani (latin)",
"ks-deva,kashmiri (devanagari)",
"lrc-iq,northern luri (iraq)",
"ms-bn,malay (brunei)",
Expand Down
26 changes: 13 additions & 13 deletions tests/dtfdayperiod.html
Original file line number Diff line number Diff line change
Expand Up @@ -267,19 +267,17 @@
let localesMatch = ""
if (method == "all") {
localesHashAll = localesHash
if (isFF) {
// only hash notate if 115+
let is115 = (CanvasRenderingContext2D.prototype.hasOwnProperty("letterSpacing"))
if (is115) {
// track FF version changes
// results
if (resultsHash == "fe9c0751") {resultsHash += s14 +" [FF115+]"+ sc
} else {resultsHash += zNEW
}
// locales
if (localesHash == "6b3f4b76") {localesHash += s14 +" [FF115+]"+ sc
} else if (isFF) {localesHash += zNEW
}
// notate new if 128+
if (isVer > 127) {
// results
if (resultsHash == "726a3f3e") { // FF134+
} else if (resultsHash == "a1b85e7a") { // FF128-133
} else {resultsHash += ' '+ zNEW
}
// locales
if (localesHash == "7f0661b3") { // FF134+: 213
} else if (localesHash == "5c9553ed") { // FF128-133: 210
} else if (isFF) {localesHash += ' '+ zNEW
}
}
} else if (method == "custom") {
Expand Down Expand Up @@ -367,6 +365,7 @@
Promise.all([
get_globals()
]).then(function(){
get_isVer()
reset_custom("min")
// add additional locales to core locales for this test
let aListExtra = [
Expand All @@ -386,6 +385,7 @@
"fr-ch,french (switzerland)",
"fr-sn,french (senegal)",
"hi-latn,hindi (latin)",
"kok-latn,konkani (latin)",
"ks-deva,kashmiri (devanagari)",
"pt-pt,portuguese (portugal)",
"ro-md,romanian (moldova)",
Expand Down
25 changes: 12 additions & 13 deletions tests/dtflistformat.html
Original file line number Diff line number Diff line change
Expand Up @@ -243,19 +243,17 @@
let localesMatch = ""
if (method == "all") {
localesHashAll = localesHash
if (isFF) {
// only hash notate if 115+
let is115 = (CanvasRenderingContext2D.prototype.hasOwnProperty("letterSpacing"))
if (is115) {
// track FF version changes
// results
if (resultsHash == "c967767a") {resultsHash += s14 +" [FF115+]"+ sc
} else {resultsHash += zNEW
}
// locales
if (localesHash == "5520ad5a") {localesHash += s14 +" [FF115+]"+ sc
} else if (isFF) {localesHash += zNEW
}
// notate new if 128+
if (isVer > 127) {
// results
if (resultsHash == "86d07210") { // FF134+
} else if (resultsHash == "c967767a") { // FF128-133
} else {resultsHash += ' '+ zNEW
}
// locales
if (localesHash == "b7e10450") { // FF134+: 145
} else if (localesHash == "5520ad5a") { // FF128-133: 140
} else if (isFF) {localesHash += ' '+ zNEW
}
}
} else if (method == "custom") {
Expand Down Expand Up @@ -325,6 +323,7 @@
Promise.all([
get_globals()
]).then(function(){
get_isVer()
// support
try {
let test = new Intl.ListFormat(undefined, {style: "short", type: "conjunction"}).format(["a","b","c"])
Expand Down
Loading

0 comments on commit dfdafda

Please sign in to comment.