From: Sven Schöling Date: Fri, 23 Feb 2018 14:32:36 +0000 (+0100) Subject: Validator: time - striktere Prüfung und tests X-Git-Tag: release-3.5.4~450 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=7f414d7b101046679e311f35c849a9ecfe60a538;p=kivitendo-erp.git Validator: time - striktere Prüfung und tests --- diff --git a/js/kivi.js b/js/kivi.js index 7c1f00a43..444892117 100644 --- a/js/kivi.js +++ b/js/kivi.js @@ -138,6 +138,10 @@ namespace("kivi", function(ns) { var parts = time.replace(/\s+/g, "").split(ns._time_format.sep); if (parts.length == 2) { + for (var idx in parts) { + if (Number.isNaN(Number.parseInt(parts[idx]))) + return undefined; + } now.setHours(parts[ns._time_format.h], parts[ns._time_format.m]); return now; } else diff --git a/js/t/kivi/parse_format_time.js b/js/t/kivi/parse_format_time.js index 901de6415..393d790c3 100644 --- a/js/t/kivi/parse_format_time.js +++ b/js/t/kivi/parse_format_time.js @@ -5,25 +5,43 @@ function custom_time(h,m) { } QUnit.test("kivi.parse_time function for German time style with colon", function( assert ) { + assert.equalTimes = function(actual, expected, message) { + console.log(this); + var result = (expected === undefined && actual === undefined) + || (expected === null && actual === null) + || (expected instanceof Date && actual instanceof Date && + expected.getHours() == actual.getHours() && + expected.getMinutes() == actual.getMinutes()); + + this.push( { + result: result, + actual: actual, + expected: expected, + message: message + } ); + } + kivi.setup_formats({ times: "hh:mm" }); - assert.deepEqual(kivi.parse_time("12:34"), custom_time(12,34)); - assert.deepEqual(kivi.parse_time("10:00"), custom_time(10,0)); - assert.deepEqual(kivi.parse_time(" 12 : 23 "), custom_time(12,23)); + assert.equalTimes(kivi.parse_time("12:34"), custom_time(12,34)); + assert.equalTimes(kivi.parse_time("10:00"), custom_time(10,0)); + assert.equalTimes(kivi.parse_time(" 12 : 23 ") - custom_time(12,23)); - assert.deepEqual(kivi.parse_time("00:20"), custom_time(0,20)); + assert.equalTimes(kivi.parse_time("00:20"), custom_time(0,20)); - assert.deepEqual(kivi.parse_time("23:60"), custom_time(23,60)); + assert.equalTimes(kivi.parse_time("23:60"), custom_time(23,60)); - assert.deepEqual(kivi.parse_time("1142"), custom_time(11,42)); + assert.equalTimes(kivi.parse_time("1142"), custom_time(11,42)); - assert.deepEqual(kivi.parse_time("Totally Invalid!"), undefined); - assert.deepEqual(kivi.parse_time("."), undefined); - assert.deepEqual(kivi.parse_time(".."), undefined); - assert.deepEqual(kivi.parse_time(":"), custom_time(0,0)); - assert.deepEqual(kivi.parse_time("::"), undefined); - assert.deepEqual(kivi.parse_time(""), null); - assert.deepEqual(kivi.parse_time("0"), new Date()); - assert.deepEqual(kivi.parse_time("29:20008"), custom_time(29,20008)); + assert.equalTimes(kivi.parse_time("Totally Invalid!"), undefined); + assert.equalTimes(kivi.parse_time("."), undefined); + assert.equalTimes(kivi.parse_time(".."), undefined); + assert.equalTimes(kivi.parse_time(":"), undefined); + assert.equalTimes(kivi.parse_time("::"), undefined); + assert.equalTimes(kivi.parse_time("aa:bb"), undefined); + assert.equalTimes(kivi.parse_time("aasd:bbaf"), undefined); + assert.equalTimes(kivi.parse_time(""), null); + assert.equalTimes(kivi.parse_time("0"), new Date()); + assert.equalTimes(kivi.parse_time("29:20008"), custom_time(29,20008)); });