Skip to content

Instantly share code, notes, and snippets.

@ronniehicks
Created February 18, 2015 02:01
Show Gist options
  • Save ronniehicks/d40d1baf5a83e70b1f0b to your computer and use it in GitHub Desktop.
Save ronniehicks/d40d1baf5a83e70b1f0b to your computer and use it in GitHub Desktop.
app.config(['$urlMatcherFactoryProvider', function ($urlMatcherFactoryProvider) {
$urlMatcherFactoryProvider.defaultSquashPolicy(true);
$urlMatcherFactoryProvider.type('nullableDate', {
encode: function (val) {
if (ng.isUndefined(val) || !ng.isDate(val) || val == null) return;
return [
val.getFullYear(),
('0' + (val.getMonth() + 1)).slice(-2),
('0' + val.getDate()).slice(-2)
].join("-");
},
decode: function (val) {
if (ng.isUndefined(val) || !ng.isDate(val) || val == null) return;
return new Date(val);
},
is: function(val) {
return val instanceof Date && !isNaN(val.valueOf());
},
equals: function (a, b) {
if (ng.isUndefined(a) || !ng.isDate(a) || a == null) return false;
if (ng.isUndefined(b) || !ng.isDate(b) || b == null) return false;
return a.toISOString() === b.toISOString();
},
pattern: /[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/
});
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment