1 QUnit.test("kivi.parse_date function for German date style with dots", function( assert ) {
2 kivi.setup_formats({ dates: "dd.mm.yy" });
4 assert.deepEqual(kivi.parse_date("01.01.2007"), new Date(2007, 0, 1));
5 assert.deepEqual(kivi.parse_date("1.1.2007"), new Date(2007, 0, 1));
6 assert.deepEqual(kivi.parse_date(" 01 . 1. 2007 "), new Date(2007, 0, 1));
8 assert.deepEqual(kivi.parse_date("29.02.2008"), new Date(2008, 1, 29));
10 assert.deepEqual(kivi.parse_date("11.12.2014"), new Date(2014, 11, 11));
12 assert.deepEqual(kivi.parse_date("25.12."), new Date((new Date).getFullYear(), 11, 25));
13 assert.deepEqual(kivi.parse_date("25.12"), new Date((new Date).getFullYear(), 11, 25));
15 assert.deepEqual(kivi.parse_date("2512"), new Date((new Date).getFullYear(), 11, 25));
16 assert.deepEqual(kivi.parse_date("25122015"), new Date(2015, 11, 25));
17 assert.deepEqual(kivi.parse_date("251215"), new Date(2015, 11, 25));
18 assert.deepEqual(kivi.parse_date("25"), new Date((new Date).getFullYear(), (new Date).getMonth(), 25));
19 assert.deepEqual(kivi.parse_date("1"), new Date((new Date).getFullYear(), (new Date).getMonth(), 1));
20 assert.deepEqual(kivi.parse_date("01"), new Date((new Date).getFullYear(), (new Date).getMonth(), 1));
22 assert.deepEqual(kivi.parse_date("Totally Invalid!"), undefined);
23 assert.deepEqual(kivi.parse_date(":"), undefined);
24 assert.deepEqual(kivi.parse_date("::"), undefined);
25 assert.deepEqual(kivi.parse_date(""), undefined);
28 QUnit.test("kivi.parse_date function for German date style with slashes", function( assert ) {
29 kivi.setup_formats({ dates: "dd/mm/yy" });
31 assert.deepEqual(kivi.parse_date("01/01/2007"), new Date(2007, 0, 1));
32 assert.deepEqual(kivi.parse_date("1/1/2007"), new Date(2007, 0, 1));
33 assert.deepEqual(kivi.parse_date(" 01 / 1/ 2007 "), new Date(2007, 0, 1));
35 assert.deepEqual(kivi.parse_date("29/02/2008"), new Date(2008, 1, 29));
37 assert.deepEqual(kivi.parse_date("11/12/2014"), new Date(2014, 11, 11));
39 assert.deepEqual(kivi.parse_date("25/12/"), new Date((new Date).getFullYear(), 11, 25));
40 assert.deepEqual(kivi.parse_date("25/12"), new Date((new Date).getFullYear(), 11, 25));
42 assert.deepEqual(kivi.parse_date("Totally Invalid!"), undefined);
45 QUnit.test("kivi.parse_date function for American date style", function( assert ) {
46 kivi.setup_formats({ dates: "mm/dd/yy" });
48 assert.deepEqual(kivi.parse_date("01/01/2007"), new Date(2007, 0, 1));
49 assert.deepEqual(kivi.parse_date("1/1/2007"), new Date(2007, 0, 1));
50 assert.deepEqual(kivi.parse_date(" 01 / 1/ 2007 "), new Date(2007, 0, 1));
52 assert.deepEqual(kivi.parse_date("02/29/2008"), new Date(2008, 1, 29));
54 assert.deepEqual(kivi.parse_date("12/11/2014"), new Date(2014, 11, 11));
56 assert.deepEqual(kivi.parse_date("12/25/"), new Date((new Date).getFullYear(), 11, 25));
57 assert.deepEqual(kivi.parse_date("12/25"), new Date((new Date).getFullYear(), 11, 25));
59 assert.deepEqual(kivi.parse_date("Totally Invalid!"), undefined);
62 QUnit.test("kivi.parse_date function for ISO date style", function( assert ) {
63 kivi.setup_formats({ dates: "yyyy-mm-dd" });
65 assert.deepEqual(kivi.parse_date("2007-01-01"), new Date(2007, 0, 1));
66 assert.deepEqual(kivi.parse_date("2007-1-1"), new Date(2007, 0, 1));
67 assert.deepEqual(kivi.parse_date(" 2007 - 1 -01 "), new Date(2007, 0, 1));
69 assert.deepEqual(kivi.parse_date("2008-02-29"), new Date(2008, 1, 29));
71 assert.deepEqual(kivi.parse_date("2014-12-11"), new Date(2014, 11, 11));
73 assert.deepEqual(kivi.parse_date("-12-25"), new Date((new Date).getFullYear(), 11, 25));
76 QUnit.test("kivi.format_date function for German date style with dots", function( assert ) {
77 kivi.setup_formats({ dates: "dd.mm.yy" });
79 assert.deepEqual(kivi.format_date(new Date(2007, 0, 1)), "01.01.2007");
80 assert.deepEqual(kivi.format_date(new Date(2008, 1, 29)), "29.02.2008");
81 assert.deepEqual(kivi.format_date(new Date(2014, 11, 11)), "11.12.2014");
83 assert.deepEqual(kivi.format_date(new Date(undefined, undefined, undefined)), undefined);
86 QUnit.test("kivi.format_date function for German date style with slashes", function( assert ) {
87 kivi.setup_formats({ dates: "dd/mm/yy" });
89 assert.deepEqual(kivi.format_date(new Date(2007, 0, 1)), "01/01/2007");
90 assert.deepEqual(kivi.format_date(new Date(2008, 1, 29)), "29/02/2008");
91 assert.deepEqual(kivi.format_date(new Date(2014, 11, 11)), "11/12/2014");
93 assert.deepEqual(kivi.format_date(new Date(undefined, undefined, undefined)), undefined);
96 QUnit.test("kivi.format_date function for American date style", function( assert ) {
97 kivi.setup_formats({ dates: "mm/dd/yy" });
99 assert.deepEqual(kivi.format_date(new Date(2007, 0, 1)), "01/01/2007");
100 assert.deepEqual(kivi.format_date(new Date(2008, 1, 29)), "02/29/2008");
101 assert.deepEqual(kivi.format_date(new Date(2014, 11, 11)), "12/11/2014");
103 assert.deepEqual(kivi.format_date(new Date(undefined, undefined, undefined)), undefined);
106 QUnit.test("kivi.format_date function for ISO date style", function( assert ) {
107 kivi.setup_formats({ dates: "yyyy-mm-dd" });
109 assert.deepEqual(kivi.format_date(new Date(2007, 0, 1)), "2007-01-01");
110 assert.deepEqual(kivi.format_date(new Date(2008, 1, 29)), "2008-02-29");
111 assert.deepEqual(kivi.format_date(new Date(2014, 11, 11)), "2014-12-11");
113 assert.deepEqual(kivi.parse_date("1225"), new Date((new Date).getFullYear(), 11, 25));
114 assert.deepEqual(kivi.parse_date("20151225"), new Date(2015, 11, 25));
115 assert.deepEqual(kivi.parse_date("151225"), new Date(2015, 11, 25));
116 assert.deepEqual(kivi.parse_date("25"), new Date((new Date).getFullYear(), (new Date).getMonth(), 25));
117 assert.deepEqual(kivi.parse_date("1"), new Date((new Date).getFullYear(), (new Date).getMonth(), 1));
118 assert.deepEqual(kivi.parse_date("01"), new Date((new Date).getFullYear(), (new Date).getMonth(), 1));
120 assert.deepEqual(kivi.format_date(new Date(undefined, undefined, undefined)), undefined);