material icon indicating copy to clipboard operation
material copied to clipboard

datepicker: works incorrectly when ng-model-options="{timezone: 'UTC'}" is set

Open vdrasutis opened this issue 2 years ago • 3 comments

Date Picker incorrectly works when ng-model-options="{timezone: 'UTC'}" is set.

Issues:

  1. When initial date loaded local date is displayed in calendar and input shows correctly UTC date. How to reproduce: Goto "Demo 1" and you will see the issue. ( my time zone is +02:00). So I set initial date to be Today and setting UTC time to 23 hours. So first time when date picker is loaded input box will show local time (incorrectly) and date picker will show date in UTC (correctly). images in the Stack Overflow link. Main point to repeat this bug to set time in UTC smalled than timezone offset difference. I.E. I set 23h in UTC, so as my timezone is +2h, then in local time would be next day 01:00h. And input box will show local time.

  2. When selecting same date few times - input box and calendar date is out of sync (in calendar local date is displayed - should be UTC) How to reproduce: Go to demo page. Then select date i.e. 2020-02-18th in date picker, then again open date picker and select same ("2020-02-18th") date after selection open again date picker and you will see that in date picker "2020-02-17th" day is selected. This also can be reproduced on official page sample "Ng Model Options Timezone" when few times selecting same date in date picker (demo: https://codepen.io/laurencijus/pen/mdqXRMe).

** Demo 1**: https://codepen.io/Drasius/pen/dyZdvoM (can reproduce booth issues) Demo 2: https://jsfiddle.net/Drasius/z51vgqr6/27/

  • My time zone: UTC/GMT +2 hours (Lithuania, Vilnius)
  • AngularJS: 1.8.2
  • AngularJS Material: 1.2.4
  • OS: Windows
  • Browsers: Chrome

Question in StackOverflow: https://stackoverflow.com/questions/71123743/angularjs-material-md-datepicker-when-using-ng-model-options-timezone-utc

vdrasutis avatar Feb 15 '22 15:02 vdrasutis

I see that you listed a couple of issues, but I don't see any detailed reproduction steps for how to reproduce the issue. They should include your current timezone and time.

That said, this repo is currently at it's End-of-Life and will soon be archived. We don't plan to release any new bug or security fixes. You can find an option for extended support on this page: https://docs.angularjs.org/misc/version-support-status.

Splaktar avatar Feb 15 '22 19:02 Splaktar

updated demo and description how to repeat booth issues

vdrasutis avatar Feb 19 '22 20:02 vdrasutis

Refactored code which should improve time zone handling and it solved Nr "2" issue. Issue nr "1" - still exists.

  • added demo to represent second issue described in this issue.

Note: fix was tested and works fine only when time zone is UTC (00:00) - did not tried passing other tz options.

vdrasutis avatar Feb 19 '22 22:02 vdrasutis