2 var today = new Date();
3 today.setMilliseconds(0);
10 QUnit.test("kivi.parse_date function for German date style with dots", function( assert ) {
11 kivi.setup_formats({ dates: "dd.mm.yy" });
13 assert.deepEqual(kivi.parse_date("01.01.2007"), new Date(2007, 0, 1));
14 assert.deepEqual(kivi.parse_date("1.1.2007"), new Date(2007, 0, 1));
15 assert.deepEqual(kivi.parse_date(" 01 . 1. 2007 "), new Date(2007, 0, 1));
17 assert.deepEqual(kivi.parse_date("29.02.2008"), new Date(2008, 1, 29));
19 assert.deepEqual(kivi.parse_date("11.12.2014"), new Date(2014, 11, 11));
21 assert.deepEqual(kivi.parse_date("25.12."), new Date((new Date).getFullYear(), 11, 25));
22 assert.deepEqual(kivi.parse_date("25.12"), new Date((new Date).getFullYear(), 11, 25));
24 assert.deepEqual(kivi.parse_date("2512"), new Date((new Date).getFullYear(), 11, 25));
25 assert.deepEqual(kivi.parse_date("25122015"), new Date(2015, 11, 25));
26 assert.deepEqual(kivi.parse_date("251215"), new Date(2015, 11, 25));
27 assert.deepEqual(kivi.parse_date("25"), new Date((new Date).getFullYear(), (new Date).getMonth(), 25));
28 assert.deepEqual(kivi.parse_date("1"), new Date((new Date).getFullYear(), (new Date).getMonth(), 1));
29 assert.deepEqual(kivi.parse_date("01"), new Date((new Date).getFullYear(), (new Date).getMonth(), 1));
31 assert.deepEqual(kivi.parse_date("Totally Invalid!"), undefined);
32 assert.deepEqual(kivi.parse_date(":"), undefined);
33 assert.deepEqual(kivi.parse_date("::"), undefined);
34 assert.deepEqual(kivi.parse_date("."), today());
35 assert.deepEqual(kivi.parse_date(".."), today());
36 assert.deepEqual(kivi.parse_date(""), null);
37 assert.deepEqual(kivi.parse_date("0"), new Date());
38 assert.deepEqual(kivi.parse_date("00"), new Date());
39 assert.deepEqual(kivi.parse_date("29.02.20008"), undefined);
42 QUnit.test("kivi.parse_date function for German date style with slashes", function( assert ) {
43 kivi.setup_formats({ dates: "dd/mm/yy" });
45 assert.deepEqual(kivi.parse_date("01/01/2007"), new Date(2007, 0, 1));
46 assert.deepEqual(kivi.parse_date("1/1/2007"), new Date(2007, 0, 1));
47 assert.deepEqual(kivi.parse_date(" 01 / 1/ 2007 "), new Date(2007, 0, 1));
49 assert.deepEqual(kivi.parse_date("29/02/2008"), new Date(2008, 1, 29));
51 assert.deepEqual(kivi.parse_date("11/12/2014"), new Date(2014, 11, 11));
53 assert.deepEqual(kivi.parse_date("25/12/"), new Date((new Date).getFullYear(), 11, 25));
54 assert.deepEqual(kivi.parse_date("25/12"), new Date((new Date).getFullYear(), 11, 25));
56 assert.deepEqual(kivi.parse_date("/"), today());
57 assert.deepEqual(kivi.parse_date("//"), today());
59 assert.deepEqual(kivi.parse_date("Totally Invalid!"), undefined);
62 QUnit.test("kivi.parse_date function for American date style", function( assert ) {
63 kivi.setup_formats({ dates: "mm/dd/yy" });
65 assert.deepEqual(kivi.parse_date("01/01/2007"), new Date(2007, 0, 1));
66 assert.deepEqual(kivi.parse_date("1/1/2007"), new Date(2007, 0, 1));
67 assert.deepEqual(kivi.parse_date(" 01 / 1/ 2007 "), new Date(2007, 0, 1));
69 assert.deepEqual(kivi.parse_date("02/29/2008"), new Date(2008, 1, 29));
71 assert.deepEqual(kivi.parse_date("12/11/2014"), new Date(2014, 11, 11));
73 assert.deepEqual(kivi.parse_date("12/25/"), new Date((new Date).getFullYear(), 11, 25));
74 assert.deepEqual(kivi.parse_date("12/25"), new Date((new Date).getFullYear(), 11, 25));
76 assert.deepEqual(kivi.parse_date("/"), today());
77 assert.deepEqual(kivi.parse_date("//"), today());
79 assert.deepEqual(kivi.parse_date("Totally Invalid!"), undefined);
82 QUnit.test("kivi.parse_date function for ISO date style", function( assert ) {
83 kivi.setup_formats({ dates: "yyyy-mm-dd" });
85 assert.deepEqual(kivi.parse_date("2007-01-01"), new Date(2007, 0, 1));
86 assert.deepEqual(kivi.parse_date("2007-1-1"), new Date(2007, 0, 1));
87 assert.deepEqual(kivi.parse_date(" 2007 - 1 -01 "), new Date(2007, 0, 1));
89 assert.deepEqual(kivi.parse_date("2008-02-29"), new Date(2008, 1, 29));
91 assert.deepEqual(kivi.parse_date("2014-12-11"), new Date(2014, 11, 11));
93 assert.deepEqual(kivi.parse_date("-12-25"), new Date((new Date).getFullYear(), 11, 25));
96 QUnit.test("kivi.format_date function for German date style with dots", function( assert ) {
97 kivi.setup_formats({ dates: "dd.mm.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)), "29.02.2008");
101 assert.deepEqual(kivi.format_date(new Date(2014, 11, 11)), "11.12.2014");
103 assert.deepEqual(kivi.format_date(new Date(undefined, undefined, undefined)), undefined);
106 QUnit.test("kivi.format_date function for German date style with slashes", function( assert ) {
107 kivi.setup_formats({ dates: "dd/mm/yy" });
109 assert.deepEqual(kivi.format_date(new Date(2007, 0, 1)), "01/01/2007");
110 assert.deepEqual(kivi.format_date(new Date(2008, 1, 29)), "29/02/2008");
111 assert.deepEqual(kivi.format_date(new Date(2014, 11, 11)), "11/12/2014");
113 assert.deepEqual(kivi.format_date(new Date(undefined, undefined, undefined)), undefined);
116 QUnit.test("kivi.format_date function for American date style", function( assert ) {
117 kivi.setup_formats({ dates: "mm/dd/yy" });
119 assert.deepEqual(kivi.format_date(new Date(2007, 0, 1)), "01/01/2007");
120 assert.deepEqual(kivi.format_date(new Date(2008, 1, 29)), "02/29/2008");
121 assert.deepEqual(kivi.format_date(new Date(2014, 11, 11)), "12/11/2014");
123 assert.deepEqual(kivi.format_date(new Date(undefined, undefined, undefined)), undefined);
126 QUnit.test("kivi.format_date function for ISO date style", function( assert ) {
127 kivi.setup_formats({ dates: "yyyy-mm-dd" });
129 assert.deepEqual(kivi.format_date(new Date(2007, 0, 1)), "2007-01-01");
130 assert.deepEqual(kivi.format_date(new Date(2008, 1, 29)), "2008-02-29");
131 assert.deepEqual(kivi.format_date(new Date(2014, 11, 11)), "2014-12-11");
133 assert.deepEqual(kivi.parse_date("1225"), new Date((new Date).getFullYear(), 11, 25));
134 assert.deepEqual(kivi.parse_date("20151225"), new Date(2015, 11, 25));
135 assert.deepEqual(kivi.parse_date("151225"), new Date(2015, 11, 25));
136 assert.deepEqual(kivi.parse_date("25"), new Date((new Date).getFullYear(), (new Date).getMonth(), 25));
137 assert.deepEqual(kivi.parse_date("1"), new Date((new Date).getFullYear(), (new Date).getMonth(), 1));
138 assert.deepEqual(kivi.parse_date("01"), new Date((new Date).getFullYear(), (new Date).getMonth(), 1));
140 assert.deepEqual(kivi.parse_date("0"), new Date());
141 assert.deepEqual(kivi.parse_date("00"), new Date());
143 assert.deepEqual(kivi.parse_date("-"), today());
144 assert.deepEqual(kivi.parse_date("--"), today());
146 assert.deepEqual(kivi.format_date(new Date(undefined, undefined, undefined)), undefined);