indrimuska / angular-moment-picker

Angular Moment Picker is an AngularJS directive for date and time picker using Moment.js.
http://indrimuska.github.io/angular-moment-picker/
MIT License
525 stars 226 forks source link

Problem with max-date / min-date and multiple date pickers #169

Open anx-ckreuzberger opened 7 years ago

anx-ckreuzberger commented 7 years ago

Hi!

I encountered a rather interesting problem when using two angular moment pickers on the same page, that have max-date and min-date linked to each other.

I've created this plunkr so you can investigate on the bug: https://plnkr.co/edit/RLUbquFfT64giCu4MVkE?p=preview

Essentially this is what happens (meta code): first.momentDate = moment(); second.momentDate = moment();

But the first date picker has max-date="first.momentDate" and second date picker has min-date="second.momentDate".

In my example when I click between last year / current year / next year, I often encounter the problem, that sometimes the first date is set to 22:59:59 instead of 23:00:00 (or 23:59:59 instead of 00:00:00, or any other :59:59 instead of :0:0 depending on your timezone).

I can overcome this by using a $timeout, but this is a hack, not a fix...

Let me know if you need any more information

anx-ckreuzberger commented 7 years ago

More Information: I can overcome this issue by setting the moment-picker attribute validate to false:

<input class="form-control"
             placeholder="Select a date..."
             moment-picker
             validate="false"
             max-view="month"
             max-date="ctrl.second.momentDate"
             ng-model="ctrl.first.momentDate"
             ng-model-options="{ updateOn: 'blur' }">

This prevents validation from happening, when the date is modified from the outside. I still believe that there is some sort of race condition happening (in the case of validate="true") which uses the modified date from ng-model, but not the modified max-date/min-date variables.

indrimuska commented 7 years ago

Very good analysis @anx-ckreuzberger, thanks even for the plunker, I'll investigate this..

vdagara commented 6 years ago

I am facing similar issue... when i set locale to "en-gb", min-date and max-date then when i open calendar, Weekday shows Wednesday though today is Tuesday.

https://plnkr.co/edit/wi8cpbxOcQ4ZO5zgK3CG?p=preview