-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
locales.test.js
34 lines (28 loc) · 951 Bytes
/
locales.test.js
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
/* eslint-env mocha */
import path from 'path'
import assert from 'power-assert'
import Chance from 'chance'
import format from '../../src/format'
import parse from '../../src/parse'
import listLocales from '../../scripts/_lib/listLocales'
const chance = new Chance(42)
listLocales().forEach(({ name, code }) => {
describe(`${name}`, () => {
chance.n(chance.date, 1).forEach(date => {
it(`parse(format(${date.toISOString()})) = ${date.toISOString()}`, () => {
const locale = require(path.join('..', '..', 'src', 'locale', code))
const formattedDate = format(
date,
locale.formatLong.date({ width: 'long' }),
{ locale }
)
const parsedDate = parse(formattedDate, 'PP', date, { locale })
console.log(formattedDate, parsedDate)
assert.deepEqual(
parsedDate.toLocaleDateString(),
date.toLocaleDateString()
)
})
})
})
})