From 21b1fba6d82436a48b687a372a4c44ba89ee6d59 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Thu, 26 Oct 2017 11:25:44 +0200 Subject: [PATCH] =?utf8?q?kivi.js:=20parse=5Fdate=20f=C3=BCllt=20fehlende?= =?utf8?q?=20Werte=20aus=20aktuellem=20Datum=20auf?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit . -> heute .. -> heute ..2016 -> heutiger Tag im Jahr 20016 --- js/kivi.js | 8 ++++---- js/t/kivi/parse_format_date.js | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/js/kivi.js b/js/kivi.js index 43e3718c2..97089645c 100644 --- a/js/kivi.js +++ b/js/kivi.js @@ -75,14 +75,14 @@ namespace("kivi", function(ns) { } date = new Date( year, - (parts[ ns._date_format.m ] || 0) * 1 - 1, // Months are 0-based. - (parts[ ns._date_format.d ] || 0) * 1 + (parts[ ns._date_format.m ] || (today.getMonth() + 1)) * 1 - 1, // Months are 0-based. + (parts[ ns._date_format.d ] || today.getDate()) * 1 ); } else if (parts.length == 2) { date = new Date( (new Date()).getFullYear(), - (parts[ (ns._date_format.m > ns._date_format.d) * 1 ] || 0) * 1 - 1, // Months are 0-based. - (parts[ (ns._date_format.d > ns._date_format.m) * 1 ] || 0) * 1 + (parts[ (ns._date_format.m > ns._date_format.d) * 1 ] || (today.getMonth() + 1)) * 1 - 1, // Months are 0-based. + (parts[ (ns._date_format.d > ns._date_format.m) * 1 ] || today.getDate()) * 1 ); } else return undefined; diff --git a/js/t/kivi/parse_format_date.js b/js/t/kivi/parse_format_date.js index 6cbc9a2b5..7fe32e69c 100644 --- a/js/t/kivi/parse_format_date.js +++ b/js/t/kivi/parse_format_date.js @@ -1,3 +1,12 @@ +function today() { + var today = new Date(); + today.setMilliseconds(0); + today.setSeconds(0); + today.setMinutes(0); + today.setHours(0); + return today; +}; + QUnit.test("kivi.parse_date function for German date style with dots", function( assert ) { kivi.setup_formats({ dates: "dd.mm.yy" }); @@ -22,6 +31,8 @@ QUnit.test("kivi.parse_date function for German date style with dots", function( assert.deepEqual(kivi.parse_date("Totally Invalid!"), undefined); assert.deepEqual(kivi.parse_date(":"), undefined); assert.deepEqual(kivi.parse_date("::"), undefined); + assert.deepEqual(kivi.parse_date("."), today()); + assert.deepEqual(kivi.parse_date(".."), today()); assert.deepEqual(kivi.parse_date(""), null); assert.deepEqual(kivi.parse_date("0"), new Date()); assert.deepEqual(kivi.parse_date("29.02.20008"), undefined); @@ -41,6 +52,9 @@ QUnit.test("kivi.parse_date function for German date style with slashes", functi assert.deepEqual(kivi.parse_date("25/12/"), new Date((new Date).getFullYear(), 11, 25)); assert.deepEqual(kivi.parse_date("25/12"), new Date((new Date).getFullYear(), 11, 25)); + assert.deepEqual(kivi.parse_date("/"), today()); + assert.deepEqual(kivi.parse_date("//"), today()); + assert.deepEqual(kivi.parse_date("Totally Invalid!"), undefined); }); @@ -58,6 +72,9 @@ QUnit.test("kivi.parse_date function for American date style", function( assert assert.deepEqual(kivi.parse_date("12/25/"), new Date((new Date).getFullYear(), 11, 25)); assert.deepEqual(kivi.parse_date("12/25"), new Date((new Date).getFullYear(), 11, 25)); + assert.deepEqual(kivi.parse_date("/"), today()); + assert.deepEqual(kivi.parse_date("//"), today()); + assert.deepEqual(kivi.parse_date("Totally Invalid!"), undefined); }); @@ -119,5 +136,8 @@ QUnit.test("kivi.format_date function for ISO date style", function( assert ) { assert.deepEqual(kivi.parse_date("1"), new Date((new Date).getFullYear(), (new Date).getMonth(), 1)); assert.deepEqual(kivi.parse_date("01"), new Date((new Date).getFullYear(), (new Date).getMonth(), 1)); + assert.deepEqual(kivi.parse_date("-"), today()); + assert.deepEqual(kivi.parse_date("--"), today()); + assert.deepEqual(kivi.format_date(new Date(undefined, undefined, undefined)), undefined); }); -- 2.20.1