From f7dff46807f77e5bd427767e1a1aa5e2937d93d0 Mon Sep 17 00:00:00 2001 From: akamfoad Date: Wed, 1 Dec 2021 12:07:52 +0300 Subject: [PATCH] add meridiem function to ku locale MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Kurdish (ku) locale has it's own form of meridiem texts which are: `AM` -> `پ.ن` `PM` -> `د.ن` The logic of determining which should be chosen is identical to the main logic from the library, the only change is localized strings for each case. Also tests are added to the corresponding locale to ensure it gets formatted correctly. --- src/locale/ku.js | 1 + test/locale/ku.test.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 test/locale/ku.test.js diff --git a/src/locale/ku.js b/src/locale/ku.js index 5f1ce6a60..07a6b2f16 100644 --- a/src/locale/ku.js +++ b/src/locale/ku.js @@ -18,6 +18,7 @@ const locale = { LLL: 'D MMMM YYYY HH:mm', LLLL: 'dddd, D MMMM YYYY HH:mm' }, + meridiem: hour => (hour < 12 ? 'پ.ن' : 'د.ن'), relativeTime: { future: 'له‌ %s', past: '%s', diff --git a/test/locale/ku.test.js b/test/locale/ku.test.js new file mode 100644 index 000000000..d3dec4c28 --- /dev/null +++ b/test/locale/ku.test.js @@ -0,0 +1,20 @@ +import MockDate from 'mockdate' +import dayjs from '../../src' +import '../../src/locale/ku' + +beforeEach(() => { + MockDate.set(new Date()) +}) + +afterEach(() => { + MockDate.reset() +}) + +it('Format meridiem correctly', () => { + for (let i = 0; i <= 23; i += 1) { + const dayjsKu = dayjs() + .startOf('day') + .add(i, 'hour') + expect(dayjsKu.locale('ku').format('h A')).toBe(`${i % 12 || 12} ${i < 12 ? 'پ.ن' : 'د.ن'}`) + } +})