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("Totally Invalid!"), undefined);
18 QUnit.test("kivi.parse_date function for German date style with slashes", function( assert ) {
19 kivi.setup_formats({ dates: "dd/mm/yy" });
21 assert.deepEqual(kivi.parse_date("01/01/2007"), new Date(2007, 0, 1));
22 assert.deepEqual(kivi.parse_date("1/1/2007"), new Date(2007, 0, 1));
23 assert.deepEqual(kivi.parse_date(" 01 / 1/ 2007 "), new Date(2007, 0, 1));
25 assert.deepEqual(kivi.parse_date("29/02/2008"), new Date(2008, 1, 29));
27 assert.deepEqual(kivi.parse_date("11/12/2014"), new Date(2014, 11, 11));
29 assert.deepEqual(kivi.parse_date("25/12/"), new Date((new Date).getFullYear(), 11, 25));
30 assert.deepEqual(kivi.parse_date("25/12"), new Date((new Date).getFullYear(), 11, 25));
32 assert.deepEqual(kivi.parse_date("Totally Invalid!"), undefined);
35 QUnit.test("kivi.parse_date function for American date style", function( assert ) {
36 kivi.setup_formats({ dates: "mm/dd/yy" });
38 assert.deepEqual(kivi.parse_date("01/01/2007"), new Date(2007, 0, 1));
39 assert.deepEqual(kivi.parse_date("1/1/2007"), new Date(2007, 0, 1));
40 assert.deepEqual(kivi.parse_date(" 01 / 1/ 2007 "), new Date(2007, 0, 1));
42 assert.deepEqual(kivi.parse_date("02/29/2008"), new Date(2008, 1, 29));
44 assert.deepEqual(kivi.parse_date("12/11/2014"), new Date(2014, 11, 11));
46 assert.deepEqual(kivi.parse_date("12/25/"), new Date((new Date).getFullYear(), 11, 25));
47 assert.deepEqual(kivi.parse_date("12/25"), new Date((new Date).getFullYear(), 11, 25));
49 assert.deepEqual(kivi.parse_date("Totally Invalid!"), undefined);
52 QUnit.test("kivi.parse_date function for ISO date style", function( assert ) {
53 kivi.setup_formats({ dates: "yyyy-mm-dd" });
55 assert.deepEqual(kivi.parse_date("2007-01-01"), new Date(2007, 0, 1));
56 assert.deepEqual(kivi.parse_date("2007-1-1"), new Date(2007, 0, 1));
57 assert.deepEqual(kivi.parse_date(" 2007 - 1 -01 "), new Date(2007, 0, 1));
59 assert.deepEqual(kivi.parse_date("2008-02-29"), new Date(2008, 1, 29));
61 assert.deepEqual(kivi.parse_date("2014-12-11"), new Date(2014, 11, 11));
63 assert.deepEqual(kivi.parse_date("-12-25"), new Date((new Date).getFullYear(), 11, 25));
66 QUnit.test("kivi.format_date function for German date style with dots", function( assert ) {
67 kivi.setup_formats({ dates: "dd.mm.yy" });
69 assert.deepEqual(kivi.format_date(new Date(2007, 0, 1)), "01.01.2007");
70 assert.deepEqual(kivi.format_date(new Date(2008, 1, 29)), "29.02.2008");
71 assert.deepEqual(kivi.format_date(new Date(2014, 11, 11)), "11.12.2014");
73 assert.deepEqual(kivi.format_date(new Date(undefined, undefined, undefined)), undefined);
76 QUnit.test("kivi.format_date function for German date style with slashes", 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 American date style", function( assert ) {
87 kivi.setup_formats({ dates: "mm/dd/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)), "02/29/2008");
91 assert.deepEqual(kivi.format_date(new Date(2014, 11, 11)), "12/11/2014");
93 assert.deepEqual(kivi.format_date(new Date(undefined, undefined, undefined)), undefined);
96 QUnit.test("kivi.format_date function for ISO date style", function( assert ) {
97 kivi.setup_formats({ dates: "yyyy-mm-dd" });
99 assert.deepEqual(kivi.format_date(new Date(2007, 0, 1)), "2007-01-01");
100 assert.deepEqual(kivi.format_date(new Date(2008, 1, 29)), "2008-02-29");
101 assert.deepEqual(kivi.format_date(new Date(2014, 11, 11)), "2014-12-11");
103 assert.deepEqual(kivi.format_date(new Date(undefined, undefined, undefined)), undefined);