From 4307ec2a1e5514276389f44340e6034ea4595b80 Mon Sep 17 00:00:00 2001 From: Pushkar Kulkarni Date: Wed, 29 Jan 2025 11:43:35 +0530 Subject: [PATCH 1/3] Modify tokenParser tests to suit CLDR 46 CLDR 46 makes changes to the knda (Kannada) and ta (Tamil) locales effectively disregarding local names for AM/PM (Kannada) and special names for afternoon. The tests have been modified to use "PM". --- test/datetime/tokenParse.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/datetime/tokenParse.test.js b/test/datetime/tokenParse.test.js index 8b5c6a8d7..cc5059950 100644 --- a/test/datetime/tokenParse.test.js +++ b/test/datetime/tokenParse.test.js @@ -901,7 +901,7 @@ test("DateTime.fromFormatExplain() parses zone correctly", () => { test("DateTime.fromFormatExplain() parses localized string with numberingSystem correctly", () => { const ex1 = DateTime.fromFormatExplain( - "೦೩-ಏಪ್ರಿಲ್-೨೦೧೯ ೧೨:೨೬:೦೭ ಅಪರಾಹ್ನ Asia/Calcutta", + "೦೩-ಏಪ್ರಿಲ್-೨೦೧೯ ೧೨:೨೬:೦೭ PM Asia/Calcutta", "dd-MMMM-yyyy hh:mm:ss a z", { locale: "kn", numberingSystem: "knda" } ); @@ -1087,7 +1087,7 @@ test("DateTime.fromFormatExplain() parses localized string with numberingSystem expect(keyCount(ex15.result)).toBe(6); const ex16 = DateTime.fromFormatExplain( - "௦௩-ஏப்ரல்-௨௦௧௯ ௦௪:௦௦:௪௧ பிற்பகல்", + "௦௩-ஏப்ரல்-௨௦௧௯ ௦௪:௦௦:௪௧ PM", "dd-MMMM-yyyy hh:mm:ss a", { locale: "ta", From 57a35ca198a7e4ea00c5fb042d200663f7504b3f Mon Sep 17 00:00:00 2001 From: Take Weiland Date: Wed, 12 Feb 2025 21:04:24 +0100 Subject: [PATCH 2/3] fix prettier formatting --- test/datetime/tokenParse.test.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/test/datetime/tokenParse.test.js b/test/datetime/tokenParse.test.js index cc5059950..24fd84afc 100644 --- a/test/datetime/tokenParse.test.js +++ b/test/datetime/tokenParse.test.js @@ -1086,14 +1086,10 @@ test("DateTime.fromFormatExplain() parses localized string with numberingSystem expect(ex15.result).toBeInstanceOf(Object); expect(keyCount(ex15.result)).toBe(6); - const ex16 = DateTime.fromFormatExplain( - "௦௩-ஏப்ரல்-௨௦௧௯ ௦௪:௦௦:௪௧ PM", - "dd-MMMM-yyyy hh:mm:ss a", - { - locale: "ta", - numberingSystem: "tamldec", - } - ); + const ex16 = DateTime.fromFormatExplain("௦௩-ஏப்ரல்-௨௦௧௯ ௦௪:௦௦:௪௧ PM", "dd-MMMM-yyyy hh:mm:ss a", { + locale: "ta", + numberingSystem: "tamldec", + }); expect(ex16.rawMatches).toBeInstanceOf(Array); expect(ex16.matches).toBeInstanceOf(Object); expect(keyCount(ex16.matches)).toBe(7); From 3833463021d5a762549c7cc1a89d49e231e8dbba Mon Sep 17 00:00:00 2001 From: Take Weiland Date: Wed, 12 Feb 2025 21:44:50 +0100 Subject: [PATCH 3/3] Fix CLDR-Version dependent tests --- .github/workflows/test.yml | 5 ++++- test/datetime/tokenParse.test.js | 19 +++++++++++++------ test/helpers.js | 15 +++++++++++++++ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 273e2ed69..3ed48e223 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,10 @@ jobs: strategy: matrix: - node-version: [20.5.1] + node-version: + - 18.20.6 # latest 18.x + - 20.18.3 # latest 20.x + - 22.14.0 # latest 22.x steps: - uses: actions/checkout@v3 diff --git a/test/datetime/tokenParse.test.js b/test/datetime/tokenParse.test.js index 24fd84afc..0bb6e2d51 100644 --- a/test/datetime/tokenParse.test.js +++ b/test/datetime/tokenParse.test.js @@ -1,6 +1,6 @@ /* global test expect */ import { DateTime } from "../../src/luxon"; -import Helpers from "../helpers"; +import Helpers, { cldrMajorVersion } from "../helpers"; import Settings from "../../src/settings"; import { ConflictingSpecificationError } from "../../src/errors"; @@ -900,8 +900,11 @@ test("DateTime.fromFormatExplain() parses zone correctly", () => { }); test("DateTime.fromFormatExplain() parses localized string with numberingSystem correctly", () => { + const cldr = cldrMajorVersion(); const ex1 = DateTime.fromFormatExplain( - "೦೩-ಏಪ್ರಿಲ್-೨೦೧೯ ೧೨:೨೬:೦೭ PM Asia/Calcutta", + cldr && cldr < 46 + ? "೦೩-ಏಪ್ರಿಲ್-೨೦೧೯ ೧೨:೨೬:೦೭ ಅಪರಾಹ್ನ Asia/Calcutta" + : "೦೩-ಏಪ್ರಿಲ್-೨೦೧೯ ೧೨:೨೬:೦೭ PM Asia/Calcutta", "dd-MMMM-yyyy hh:mm:ss a z", { locale: "kn", numberingSystem: "knda" } ); @@ -1086,10 +1089,14 @@ test("DateTime.fromFormatExplain() parses localized string with numberingSystem expect(ex15.result).toBeInstanceOf(Object); expect(keyCount(ex15.result)).toBe(6); - const ex16 = DateTime.fromFormatExplain("௦௩-ஏப்ரல்-௨௦௧௯ ௦௪:௦௦:௪௧ PM", "dd-MMMM-yyyy hh:mm:ss a", { - locale: "ta", - numberingSystem: "tamldec", - }); + const ex16 = DateTime.fromFormatExplain( + cldr && cldr < 45 ? "௦௩-ஏப்ரல்-௨௦௧௯ ௦௪:௦௦:௪௧ பிற்பகல்" : "௦௩-ஏப்ரல்-௨௦௧௯ ௦௪:௦௦:௪௧ PM", + "dd-MMMM-yyyy hh:mm:ss a", + { + locale: "ta", + numberingSystem: "tamldec", + } + ); expect(ex16.rawMatches).toBeInstanceOf(Array); expect(ex16.matches).toBeInstanceOf(Object); expect(keyCount(ex16.matches)).toBe(7); diff --git a/test/helpers.js b/test/helpers.js index b3258e944..c7f3a891a 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -76,3 +76,18 @@ exports.setUnset = function (prop) { exports.atHour = function (hour) { return DateTime.fromObject({ year: 2017, month: 5, day: 25 }).startOf("day").set({ hour }); }; + +exports.cldrMajorVersion = function () { + try { + const cldr = process?.versions?.cldr; + if (cldr) { + const match = cldr.match(/^(\d+)\./); + if (match) { + return parseInt(match[1]); + } + } + return null; + } catch { + return null; + } +};