|
1 | 1 | import { testSingleCase, testUnexpectedResult } from "../test_util";
|
2 | 2 | import * as chrono from "../../src";
|
3 | 3 |
|
4 |
| -test("Test - Single Expression Start with Year", function () { |
| 4 | +test("Test - Single Expression (yyyy/MM/dd)", function () { |
5 | 5 | testSingleCase(chrono, "2012/8/10", new Date(2012, 7, 10), (result) => {
|
6 | 6 | expect(result.start).not.toBeNull();
|
7 | 7 | expect(result.start.get("year")).toBe(2012);
|
@@ -41,7 +41,7 @@ test("Test - Single Expression Start with Year", function () {
|
41 | 41 | });
|
42 | 42 | });
|
43 | 43 |
|
44 |
| -test("Test - Single Expression Start with Year and Month Name", function () { |
| 44 | +test("Test - Single Expression with month name (yyyy/MMM/dd)", function () { |
45 | 45 | testSingleCase(chrono, "2012/Aug/10", new Date(2012, 7, 10), (result) => {
|
46 | 46 | expect(result.start).not.toBeNull();
|
47 | 47 | expect(result.start.get("year")).toBe(2012);
|
@@ -73,8 +73,29 @@ test("Test - Single Expression Start with Year and Month Name", function () {
|
73 | 73 | });
|
74 | 74 | });
|
75 | 75 |
|
76 |
| -test("Test - Negative year-month-day like pattern", function () { |
77 |
| - testUnexpectedResult(chrono, "2012-80-10", new Date(2012, 7, 10)); |
| 76 | +test("Test - Allow swap date/month order in casual mode", () => { |
| 77 | + testUnexpectedResult(chrono.strict, "2024/13/1"); |
| 78 | + testUnexpectedResult(chrono.strict, "2024-13-01"); |
78 | 79 |
|
| 80 | + testSingleCase(chrono.casual, "2024/13/1", new Date(2012, 7, 10), (result) => { |
| 81 | + expect(result.start.get("year")).toBe(2024); |
| 82 | + expect(result.start.get("month")).toBe(1); |
| 83 | + expect(result.start.get("day")).toBe(13); |
| 84 | + }); |
| 85 | + |
| 86 | + testSingleCase(chrono.casual, "2024-13-01", new Date(2012, 7, 10), (result) => { |
| 87 | + expect(result.start.get("year")).toBe(2024); |
| 88 | + expect(result.start.get("month")).toBe(1); |
| 89 | + expect(result.start.get("day")).toBe(13); |
| 90 | + }); |
| 91 | +}); |
| 92 | + |
| 93 | +test("Test - Not parse unlikely xxxx-xx-xx pattern", function () { |
| 94 | + testUnexpectedResult(chrono, "2012/80/10", new Date(2012, 7, 10)); |
79 | 95 | testUnexpectedResult(chrono, "2012 80 10", new Date(2012, 7, 10));
|
80 | 96 | });
|
| 97 | + |
| 98 | +test("Test - Not parse impossible dates", function () { |
| 99 | + testUnexpectedResult(chrono, "2014-08-32"); |
| 100 | + testUnexpectedResult(chrono, "2014-02-30"); |
| 101 | +}); |
0 commit comments