Last active
November 1, 2016 19:10
-
-
Save marcomafessolli/4b5289fdab5a9790ec32 to your computer and use it in GitHub Desktop.
UTC parser for mdDatePicker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
angular.module('m.utc') | |
.directive('utcParser', function () { | |
function link(scope, element, attrs, ngModel) { | |
var parser = function (val) { | |
val = moment.utc(val).format(); | |
return val; | |
}; | |
var formatter = function (val) { | |
if (!val) { | |
return val; | |
} | |
val = moment(val).toDate(); | |
return val; | |
}; | |
ngModel.$parsers.unshift(parser); | |
ngModel.$formatters.unshift(formatter); | |
} | |
return { | |
require: 'ngModel', | |
link: link, | |
restrict: 'A' | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
val = new Date(val);
was causing the displaying date substracting a day, so I changed it to:val = moment(val).toDate();
After that, worked like a charm.