-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix] pattern year-month-day handling
- Loading branch information
Wanasit Tanakitrungruang
committed
Oct 25, 2020
1 parent
591e0a1
commit 76d493b
Showing
4 changed files
with
90 additions
and
58 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
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
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,80 @@ | ||
import { testSingleCase, testUnexpectedResult } from "../test_util"; | ||
import * as chrono from "../../src"; | ||
|
||
test("Test - Single Expression Start with Year", function () { | ||
testSingleCase(chrono, "2012/8/10", new Date(2012, 7, 10), (result) => { | ||
expect(result.start).not.toBeNull(); | ||
expect(result.start.get("year")).toBe(2012); | ||
expect(result.start.get("month")).toBe(8); | ||
expect(result.start.get("day")).toBe(10); | ||
|
||
expect(result.index).toBe(0); | ||
expect(result.text).toBe("2012/8/10"); | ||
|
||
expect(result.start).toBeDate(new Date(2012, 8 - 1, 10, 12)); | ||
}); | ||
|
||
testSingleCase(chrono, "The Deadline is 2012/8/10", new Date(2012, 7, 10), (result) => { | ||
expect(result.index).toBe(16); | ||
expect(result.text).toBe("2012/8/10"); | ||
|
||
expect(result.start).toBeDate(new Date(2012, 7, 10, 12)); | ||
}); | ||
|
||
testSingleCase(chrono.strict, "2014/2/28", (result) => { | ||
expect(result.text).toBe("2014/2/28"); | ||
}); | ||
|
||
testSingleCase(chrono.strict, "2014/12/28", (result) => { | ||
expect(result.text).toBe("2014/12/28"); | ||
expect(result).toBeDate(new Date(2014, 12 - 1, 28, 12)); | ||
}); | ||
|
||
testSingleCase(chrono.strict, "2014.12.28", (result) => { | ||
expect(result.text).toBe("2014.12.28"); | ||
expect(result).toBeDate(new Date(2014, 12 - 1, 28, 12)); | ||
}); | ||
|
||
testSingleCase(chrono.strict, "2014 12 28", (result) => { | ||
expect(result.text).toBe("2014 12 28"); | ||
expect(result).toBeDate(new Date(2014, 12 - 1, 28, 12)); | ||
}); | ||
}); | ||
|
||
test("Test - Single Expression Start with Year and Month Name", function () { | ||
testSingleCase(chrono, "2012/Aug/10", new Date(2012, 7, 10), (result) => { | ||
expect(result.start).not.toBeNull(); | ||
expect(result.start.get("year")).toBe(2012); | ||
expect(result.start.get("month")).toBe(8); | ||
expect(result.start.get("day")).toBe(10); | ||
|
||
expect(result.index).toBe(0); | ||
expect(result.text).toBe("2012/Aug/10"); | ||
|
||
expect(result.start).toBeDate(new Date(2012, 8 - 1, 10, 12)); | ||
}); | ||
|
||
testSingleCase(chrono, "The Deadline is 2012/aug/10", new Date(2012, 7, 10), (result) => { | ||
expect(result.index).toBe(16); | ||
expect(result.text).toBe("2012/aug/10"); | ||
|
||
expect(result.start).toBeDate(new Date(2012, 8 - 1, 10, 12)); | ||
}); | ||
|
||
testSingleCase(chrono, "The Deadline is 2018 March 18", new Date(2012, 7, 10), (result) => { | ||
expect(result.index).toBe(16); | ||
expect(result.text).toBe("2018 March 18"); | ||
|
||
expect(result.start.get("year")).toBe(2018); | ||
expect(result.start.get("month")).toBe(3); | ||
expect(result.start.get("day")).toBe(18); | ||
|
||
expect(result).toBeDate(new Date(2018, 3 - 1, 18, 12)); | ||
}); | ||
}); | ||
|
||
test("Test - Negative year-month-day like pattern", function () { | ||
testUnexpectedResult(chrono, "2012-80-10", new Date(2012, 7, 10)); | ||
|
||
testUnexpectedResult(chrono, "2012 80 10", new Date(2012, 7, 10)); | ||
}); |
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