-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Expand file tree
/
Copy pathen.test.js
More file actions
44 lines (40 loc) · 1.48 KB
/
Copy pathen.test.js
File metadata and controls
44 lines (40 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import moment from 'moment'
import dayjs from '../../src'
import '../../src/locale/en'
import '../../src/locale/en-gb'
import '../../src/locale/en-in'
import '../../src/locale/en-tt'
import '../../src/locale/en-ca'
import '../../src/locale/en-ie'
import '../../src/locale/en-il'
import '../../src/locale/en-sg'
import localizedFormat from '../../src/plugin/localizedFormat'
import advancedFormat from '../../src/plugin/advancedFormat'
dayjs.extend(localizedFormat)
dayjs.extend(advancedFormat)
const locales = [
{ locale: 'en', expectedDate: '12/25/2019' },
{ locale: 'en-gb', expectedDate: '25/12/2019' },
{ locale: 'en-in', expectedDate: '25/12/2019' },
{ locale: 'en-tt', expectedDate: '25/12/2019' }
]
describe('English date formats', () => {
locales.forEach((locale) => {
it(`should correctly format date with locale - ${locale.locale}`, () => {
const dayjsWithLocale = dayjs('2019-12-25').locale(locale.locale)
expect(dayjsWithLocale.format('L')).toEqual(locale.expectedDate)
})
})
})
describe('English ordinal (Do) parity with moment', () => {
const ordinalLocales = ['en-ca', 'en-ie', 'en-il', 'en-sg']
ordinalLocales.forEach((locale) => {
it(`should format the ordinal day of month like moment - ${locale}`, () => {
for (let d = 1; d <= 31; d += 1) {
const date = `2021-01-${String(d).padStart(2, '0')}`
expect(dayjs(date).locale(locale).format('Do'))
.toEqual(moment(date).locale(locale).format('Do'))
}
})
})
})