Support ng-model-options with datepicker
We should support ng-model-options with the datepicker
In particular, we should support
- [x]
allowInvalid - [x]
updateOn - [x]
timezone
I would really like to set UTC timezone instead of local or without time/timezone when setting a date using the datepicker!
:+1:
@maxdeviant, please don't add +1 to issue threads without providing further benefit to the conversation. All it does is add clutter to the thread. Thanks.
We know this is something users want and fully intend to implement it. We have a lot on our plates at the moment trying to get 1.0 out the door.
I should also add that we welcome well-thought and well-developed PRs if you really want/need this feature sooner rather than later.
My apologies. It's a bit of a force of habit, at this point.
timezone support is what I am particularly interested in.
I fixed my issue with timezone for now with this directive. Posting here in case any one needs.
https://gist.github.com/sandeepthomas/78f2de3f0f8f21869f91
It removes the timezone and converts the date to epoch/unix time.
For firebase timestamps I am using this directive.
.directive('timestamp', function($filter) {
return {
restrict: 'A',
require: ['ngModel'],
link: function link(scope, element, attr, ctrls) {
var ngModelController = ctrls[0];
var format = attr.uibDatepickerPopup;
if (format) {
ngModelController.$parsers.push(function(viewValue) {
if (!viewValue) {
return undefined;
}
// Strip off timezone offset
if (angular.isFunction(viewValue.getTime)) {
viewValue.setMinutes(viewValue.getMinutes() - viewValue.getTimezoneOffset());
return viewValue.getTime();
} else {
return undefined;
}
});
ngModelController.$formatters.push(function(modelValue) {
if (!modelValue) {
return undefined;
}
// Display the actual time, not local time
return $filter('date')(modelValue, format, '+00:00');
});
}
}
};
})
@davious nice work sir, I just played with your timezone commit and I like it! There are a couple of issues I noticed: the calendar is ahead by one day, and the time moves ahead by one hour when you select a DST date (i.e.: March 7 vs March 14)

DST problem - it changed the time from 8 to 9:

I was working on the timezone issue locally as well, as it turns out to be quite tricky - I have it completely working for the inline datepicker, but not the one in the popup.
I also have to rejig the tests.
For anyone working on this issue - a new method should be added to the dateParser service that essentially copy/pastes this mechanism from Angular: https://github.com/angular/angular.js/blob/master/src/Angular.js#L1207-L1224
@davious Want any help on this?
@mjonas87 The timezone work is committed onto master via @09098f8
@paulflo150 according to http://stackoverflow.com/questions/16946002/javascript-time-zone-is-wrong-for-past-daylight-saving-time-transition-rules/16951442#16951442 there is a design flaw in ECMAScript that makes DST handling flaky. Perhaps this explains the issue you experienced.
Regarding updateOn: blur support - I also can’t update past 0.14.x now as our date-pickers stop working. The scenario we’d like is to have the blur functionality on the input field but still want the field updated when the user makes a selection from the popup. At the moment the same ng-model-options get used for both and the popup selection no longer works.
Happy to look at a PR but not sure what the preferred approach would be. A couple of potential solutions:
-
Would it make sense to always specify or add {updateOn: default} when constructing the popup? I’m struggling to think of a scenario where delaying date selection from the pop-up would be desirable. This might at least be a sensible interim solution before defining more comprehensive updateOn support.
-
Add additional config option for popupModelOptions that will override (or merge) the options used when creating the uib-datepicker-popup-wrap. Currently the ngModelOptions provided in datepicker-options are only used if they are not already set elsewhere.
Either of those sound acceptable?
I have a drop down containing various time zones. when i select a timezone, the datepicker should be updated automatically. Is it possible to adjust ui-datepicker for selected timezone
I was just following up on @mlev 's idea (1) for supporting updateOn: blur - for me everything works as expected when i just remove the line in popup.js where ng-model-options are passed to popupEl. Probably there is a use-case for having ng-model-options on the popup, but i dont see one for specifying updateOn.
I'd be happy to provide a PR, if there are no further concerns about this approach. What do you think, @wesleycho?
Yes, please! This is causing some frustrating issues for me right now. @czosel && @wesleycho
The timezone issue is fixed. You can use:
ng-model-options="{timezone: 'utc'}"
To get a datepicker without timezone calculation.
I'm not sure what would be desired exactly for updateOn - would need to investigate.
I welcome any PRs that make sense though with tests to make it clear what is desired.
@wesleycho Alright, i'll try to come up with a PR containing some tests. If you find any use for updateOn, please let me know!
To give an update, updateOn support should be fixed as of #5933 in master, to be released for 2.0.0. getterSetter is the last piece of the puzzle, and shouldn't be too bad to implement if anyone wants to take a stab at it.