Skip to content

Instantly share code, notes, and snippets.

@marcomafessolli
Last active November 1, 2016 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcomafessolli/4b5289fdab5a9790ec32 to your computer and use it in GitHub Desktop.
Save marcomafessolli/4b5289fdab5a9790ec32 to your computer and use it in GitHub Desktop.
UTC parser for mdDatePicker
'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'
}
});
@diosney
Copy link

diosney commented Mar 6, 2016

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.

@marcomafessolli
Copy link
Author

@diosney thank you

@p1tt1
Copy link

p1tt1 commented Nov 1, 2016

you must add priority: 1 to the directive.

angular/material#9747

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment