}
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;
+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" });
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);
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);
});
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);
});
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);
});