Skip to content

Instantly share code, notes, and snippets.

@nsilvah
Created April 24, 2015 15:23
Show Gist options
  • Save nsilvah/a7a31f017de098a79f38 to your computer and use it in GitHub Desktop.
Save nsilvah/a7a31f017de098a79f38 to your computer and use it in GitHub Desktop.
DatePicker directive to fix timezone issues
app.directive('datepickerLocaldate', [function () {
var directive = {
require: 'ngModel',
link: link
};
return directive;
function link(scope, element, attr, ngModel) {
var converted = false;
scope.$watch(
function(){
return ngModel.$modelValue;
},
function(modelValue){
if(!converted && modelValue){
converted=true;
var dt = new Date(modelValue);
if(dt.getTimezoneOffset() > 0)
dt.setMinutes(dt.getMinutes() + dt.getTimezoneOffset());
ngModel.$modelValue = dt;
ngModel.$render();
}
});
}
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment