Skip to content

Commit

Permalink
add meridiem function to ku locale
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
akamfoad committed Dec 1, 2021
1 parent 5a108ff commit f7dff46
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/locale/ku.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
20 changes: 20 additions & 0 deletions test/locale/ku.test.js
Original file line number Diff line number Diff line change
@@ -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 ? 'پ.ن' : 'د.ن'}`)
}
})

0 comments on commit f7dff46

Please sign in to comment.