Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a round-trip test for formatting and parsing dates in all locales
- Loading branch information
1 parent
555ff27
commit 15949b1
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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() | ||
) | ||
}) | ||
}) | ||
}) | ||
}) |