|
| 1 | +import * as chrono from "../../src"; |
| 2 | +import { testSingleCase, testUnexpectedResult } from "../test_util"; |
| 3 | + |
| 4 | +// test("Test - fr - modifier mandatory just after", function () { |
| 5 | +// testUnexpectedResult(chrono.de, "le mois d'avril"); |
| 6 | +// |
| 7 | +// testUnexpectedResult(chrono.de, "le mois d'avril prochain"); |
| 8 | +// }); |
| 9 | + |
| 10 | +test("Test - de - relative date", function () { |
| 11 | + testSingleCase(chrono.de, "kommende Woche", new Date(2017, 5 - 1, 12), (result, text) => { |
| 12 | + expect(result.text).toBe(text); |
| 13 | + expect(result.start.get("year")).toBe(2017); |
| 14 | + expect(result.start.get("month")).toBe(5); |
| 15 | + expect(result.start.get("day")).toBe(19); |
| 16 | + }); |
| 17 | + |
| 18 | + testSingleCase(chrono.de, "in 2 Wochen", new Date(2017, 5 - 1, 12, 18, 11), (result, text) => { |
| 19 | + expect(result.text).toBe(text); |
| 20 | + expect(result.start.get("year")).toBe(2017); |
| 21 | + expect(result.start.get("month")).toBe(5); |
| 22 | + expect(result.start.get("day")).toBe(26); |
| 23 | + expect(result.start.get("hour")).toBe(18); |
| 24 | + expect(result.start.get("minute")).toBe(11); |
| 25 | + }); |
| 26 | + |
| 27 | + testSingleCase(chrono.de, "in drei Wochen", new Date(2017, 5 - 1, 12), (result, text) => { |
| 28 | + expect(result.text).toBe(text); |
| 29 | + expect(result.start.get("year")).toBe(2017); |
| 30 | + expect(result.start.get("month")).toBe(6); |
| 31 | + expect(result.start.get("day")).toBe(2); |
| 32 | + }); |
| 33 | + |
| 34 | + testSingleCase(chrono.de, "letzten Monat", new Date(2017, 5 - 1, 12), (result, text) => { |
| 35 | + expect(result.text).toBe(text); |
| 36 | + expect(result.start.get("year")).toBe(2017); |
| 37 | + expect(result.start.get("month")).toBe(4); |
| 38 | + expect(result.start.get("day")).toBe(12); |
| 39 | + }); |
| 40 | + |
| 41 | + testSingleCase(chrono.de, "in den 30 vorangegangenen Tagen", new Date(2017, 5 - 1, 12), (result, text) => { |
| 42 | + expect(result.text).toBe("30 vorangegangenen Tagen"); |
| 43 | + expect(result.start.get("year")).toBe(2017); |
| 44 | + expect(result.start.get("month")).toBe(4); |
| 45 | + expect(result.start.get("day")).toBe(12); |
| 46 | + }); |
| 47 | + |
| 48 | + testSingleCase(chrono.de, "die vergangenen 24 Stunden", new Date(2017, 5 - 1, 12, 11, 27), (result, text) => { |
| 49 | + expect(result.text).toBe("vergangenen 24 Stunden"); |
| 50 | + expect(result.start.get("year")).toBe(2017); |
| 51 | + expect(result.start.get("month")).toBe(5); |
| 52 | + expect(result.start.get("day")).toBe(11); |
| 53 | + expect(result.start.get("hour")).toBe(11); |
| 54 | + expect(result.start.get("minute")).toBe(27); |
| 55 | + }); |
| 56 | + |
| 57 | + testSingleCase(chrono.de, "in den folgenden 90 sekunden", new Date(2017, 5 - 1, 12, 11, 27, 3), (result, text) => { |
| 58 | + expect(result.text).toBe("folgenden 90 sekunden"); |
| 59 | + expect(result.start.get("year")).toBe(2017); |
| 60 | + expect(result.start.get("month")).toBe(5); |
| 61 | + expect(result.start.get("day")).toBe(12); |
| 62 | + expect(result.start.get("hour")).toBe(11); |
| 63 | + expect(result.start.get("minute")).toBe(28); |
| 64 | + expect(result.start.get("second")).toBe(33); |
| 65 | + }); |
| 66 | + |
| 67 | + testSingleCase(chrono.de, "die letzten acht Minuten", new Date(2017, 5 - 1, 12, 11, 27), (result, text) => { |
| 68 | + expect(result.text).toBe("letzten acht Minuten"); |
| 69 | + expect(result.start.get("year")).toBe(2017); |
| 70 | + expect(result.start.get("month")).toBe(5); |
| 71 | + expect(result.start.get("day")).toBe(12); |
| 72 | + expect(result.start.get("hour")).toBe(11); |
| 73 | + expect(result.start.get("minute")).toBe(19); |
| 74 | + expect(result.start.get("second")).toBe(0); |
| 75 | + }); |
| 76 | + |
| 77 | + testSingleCase(chrono.de, "letztes Quartal", new Date(2017, 5 - 1, 12, 11, 27), (result, text) => { |
| 78 | + expect(result.text).toBe(text); |
| 79 | + expect(result.start.get("year")).toBe(2017); |
| 80 | + expect(result.start.get("month")).toBe(2); |
| 81 | + expect(result.start.get("day")).toBe(12); |
| 82 | + expect(result.start.get("hour")).toBe(11); |
| 83 | + expect(result.start.get("minute")).toBe(27); |
| 84 | + expect(result.start.get("second")).toBe(0); |
| 85 | + |
| 86 | + expect(result.start.isCertain("month")).toBeFalsy(); |
| 87 | + expect(result.start.isCertain("day")).toBeFalsy(); |
| 88 | + expect(result.start.isCertain("hour")).toBeFalsy(); |
| 89 | + expect(result.start.isCertain("minute")).toBeFalsy(); |
| 90 | + expect(result.start.isCertain("second")).toBeFalsy(); |
| 91 | + }); |
| 92 | + |
| 93 | + testSingleCase(chrono.de, "kommendes Jahr", new Date(2017, 5 - 1, 12, 11, 27), (result, text) => { |
| 94 | + expect(result.text).toBe(text); |
| 95 | + expect(result.start.get("year")).toBe(2018); |
| 96 | + expect(result.start.get("month")).toBe(5); |
| 97 | + expect(result.start.get("day")).toBe(12); |
| 98 | + expect(result.start.get("hour")).toBe(11); |
| 99 | + expect(result.start.get("minute")).toBe(27); |
| 100 | + expect(result.start.get("second")).toBe(0); |
| 101 | + |
| 102 | + expect(result.start.isCertain("month")).toBeFalsy(); |
| 103 | + expect(result.start.isCertain("day")).toBeFalsy(); |
| 104 | + expect(result.start.isCertain("hour")).toBeFalsy(); |
| 105 | + expect(result.start.isCertain("minute")).toBeFalsy(); |
| 106 | + expect(result.start.isCertain("second")).toBeFalsy(); |
| 107 | + }); |
| 108 | +}); |
0 commit comments