Skip to content

Commit

Permalink
Modify tokenParser tests to suit CLDR 46 (#1680)
Browse files Browse the repository at this point in the history
* 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 the expected format based on CLDR version.
The test matrix in CI has been extended to latest Node.JS versions.

---------

Co-authored-by: Take Weiland <[email protected]>
  • Loading branch information
pushkarnk and diesieben07 authored Feb 12, 2025
1 parent b952fc5 commit aedc7bd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions test/datetime/tokenParse.test.js
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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(
"೦೩-ಏಪ್ರಿಲ್-೨೦೧೯ ೧೨:೨೬:೦೭ ಅಪರಾಹ್ನ Asia/Calcutta",
cldr && cldr < 46
? "೦೩-ಏಪ್ರಿಲ್-೨೦೧೯ ೧೨:೨೬:೦೭ ಅಪರಾಹ್ನ Asia/Calcutta"
: "೦೩-ಏಪ್ರಿಲ್-೨೦೧೯ ೧೨:೨೬:೦೭ PM Asia/Calcutta",
"dd-MMMM-yyyy hh:mm:ss a z",
{ locale: "kn", numberingSystem: "knda" }
);
Expand Down Expand Up @@ -1087,7 +1090,7 @@ test("DateTime.fromFormatExplain() parses localized string with numberingSystem
expect(keyCount(ex15.result)).toBe(6);

const ex16 = DateTime.fromFormatExplain(
"௦௩-ஏப்ரல்-௨௦௧௯ ௦௪:௦௦:௪௧ பிற்பகல்",
cldr && cldr < 45 ? "௦௩-ஏப்ரல்-௨௦௧௯ ௦௪:௦௦:௪௧ பிற்பகல்" : "௦௩-ஏப்ரல்-௨௦௧௯ ௦௪:௦௦:௪௧ PM",
"dd-MMMM-yyyy hh:mm:ss a",
{
locale: "ta",
Expand Down
15 changes: 15 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

0 comments on commit aedc7bd

Please sign in to comment.