- date = new Date(
- ((parts[ ns._date_format.y ] || 0) * 1) || (new Date()).getFullYear(),
- (parts[ ns._date_format.m ] || 0) * 1 - 1, // Months are 0-based.
- (parts[ ns._date_format.d ] || 0) * 1
- );
+ var today = new Date();
+
+ // without separator?
+ // assume fixed pattern, and extract parts again
+ if (parts.length == 1) {
+ date = parts[0];
+ parts = date.match(/../g);
+ if (date.length == 8) {
+ parts[ns._date_format.y] += parts.splice(ns._date_format.y + 1, 1)
+ }
+ else
+ if (date.length == 6 || date.length == 4) {
+ }
+ else
+ if (date.length == 1 || date.length == 2) {
+ parts = []
+ parts[ ns._date_format.y ] = today.getFullYear();
+ parts[ ns._date_format.m ] = today.getMonth() + 1;
+ parts[ ns._date_format.d ] = date;
+ }
+ else {
+ return undefined;
+ }
+ }
+
+ if (parts.length == 3) {
+ var year = +parts[ ns._date_format.y ] || 0 * 1 || (new Date()).getFullYear();
+ if (year > 9999)
+ return undefined;
+ if (year < 100) {
+ year += year > 70 ? 1900 : 2000;
+ }
+ date = new Date(
+ year,
+ (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 ] || (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;