Skip to content

Commit d726bed

Browse files
fix(): Built-in date type uses local time zone
1 parent b267ecd commit d726bed

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/urlMatcherFactory.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,6 @@ function $UrlMatcherFactory() {
563563

564564
function valToString(val) { return val != null ? val.toString().replace(/\//g, "%2F") : val; }
565565
function valFromString(val) { return val != null ? val.toString().replace(/%2F/g, "/") : val; }
566-
function angularEquals(left, right) { return angular.equals(left, right); }
567566
// TODO: in 1.0, make string .is() return false if value is undefined by default.
568567
// function regexpMatches(val) { /*jshint validthis:true */ return isDefined(val) && this.pattern.test(val); }
569568
function regexpMatches(val) { /*jshint validthis:true */ return this.pattern.test(val); }
@@ -588,16 +587,22 @@ function $UrlMatcherFactory() {
588587
pattern: /0|1/
589588
},
590589
date: {
591-
encode: function (val) { return [
590+
encode: function (val) {
591+
return [
592592
val.getFullYear(),
593593
('0' + (val.getMonth() + 1)).slice(-2),
594594
('0' + val.getDate()).slice(-2)
595595
].join("-");
596596
},
597-
decode: function (val) { return new Date(val); },
597+
decode: function (val) {
598+
if (this.is(val)) return val;
599+
var match = this.capture.exec(val);
600+
return match ? new Date(match[1], match[2] - 1, match[3]) : undefined;
601+
},
598602
is: function(val) { return val instanceof Date && !isNaN(val.valueOf()); },
599603
equals: function (a, b) { return a.toISOString() === b.toISOString(); },
600-
pattern: /[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/
604+
pattern: /[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,
605+
capture: /([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/
601606
}
602607
};
603608

0 commit comments

Comments
 (0)