angular-moment-picker icon indicating copy to clipboard operation
angular-moment-picker copied to clipboard

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

Open anx-ckreuzberger opened this issue 7 years ago • 3 comments

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 avatar May 02 '17 09:05 anx-ckreuzberger

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.

anx-ckreuzberger avatar May 02 '17 10:05 anx-ckreuzberger

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

indrimuska avatar May 07 '17 11:05 indrimuska

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

vdagara avatar Aug 21 '18 12:08 vdagara