Skip to content

Commit 3a1265d

Browse files
author
ericreis
committed
Add test to p+ tokens date parsing
1 parent 060d097 commit 3a1265d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/date_utils_test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import {
1919
} from "../src/date_utils";
2020
import setMinutes from "date-fns/setMinutes";
2121
import setHours from "date-fns/setHours";
22+
import ptBR from "date-fns/locale/pt-BR";
23+
import { registerLocale } from "../src/date_utils";
24+
25+
registerLocale("pt-BR", ptBR);
2226

2327
describe("date_utils", function() {
2428
describe("newDate", function() {
@@ -393,6 +397,25 @@ describe("date_utils", function() {
393397

394398
expect(parseDate(value, dateFormat, null, false)).to.not.be.null;
395399
});
400+
401+
it("should parse date based on locale", () => {
402+
const value = "26/05/1995";
403+
const dateFormat = "P";
404+
405+
const expected = new Date("05/26/1995");
406+
const actual = parseDate(value, dateFormat, "pt-BR", false);
407+
408+
assert(isEqual(actual, expected));
409+
});
410+
411+
it("should not parse date based on locale without a given locale", () => {
412+
const value = "26/05/1995";
413+
const dateFormat = "P";
414+
415+
const actual = parseDate(value, dateFormat, null, false);
416+
417+
expect(actual).to.be.null;
418+
});
396419
});
397420

398421
describe("isMonthinRange", () => {

0 commit comments

Comments
 (0)