Created
April 24, 2015 15:23
-
-
Save nsilvah/a7a31f017de098a79f38 to your computer and use it in GitHub Desktop.
DatePicker directive to fix timezone issues
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
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