Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

datepicker: md-calendar panel should respect ng-model-options #10598

Closed
ericsvendsen opened this issue Apr 19, 2017 · 13 comments · Fixed by #11949 or #11951
Closed

datepicker: md-calendar panel should respect ng-model-options #10598

ericsvendsen opened this issue Apr 19, 2017 · 13 comments · Fixed by #11949 or #11951
Assignees
Labels
has: Pull Request A PR has been created to address this issue i18n: localization This issue is related to internationalization P2: required Issues that must be fixed. type: enhancement
Milestone

Comments

@ericsvendsen
Copy link

ericsvendsen commented Apr 19, 2017

Actual Behavior:

  • What is the issue? *
    An md-datepicker with the timezone set to UTC still shows the localized date as selected when viewing the popup calendar.
  • What is the expected behavior?
    The popup calendar should highlight the correct date in the context of the model's timezone

CodePen (or steps to reproduce the issue): *

  • CodePen Demo which shows your issue:
    http://codepen.io/anon/pen/NjxgmR
  • Details:
    Click the down arrow or the calendar icon to see that the previous day is shown as selected in the calendar view rather than the specified day.

AngularJS Versions: *

  • AngularJS Version:1.6.4
  • AngularJS Material Version:1.1.3

Additional Information:

  • Browser Type: *Chrome
  • Browser Version: *57.0.2987.133
  • OS: *MacOS
  • Stack Traces:NA
@SocVi100
Copy link

I'm hitting the same error since I updated to v1.1.4 yesterday. This wasn't happening on v1.1.1 so it may be a regression... On my timezone the datepicker show one day less than the actual date.
@topherfangio I remember that this bug was solved some months ago, maybe it's been a bad merge lately?

@rajathms
Copy link

@ericsvendsen @SocVi100 Guys you found the solution or a work around for it.
same issue here, material version 1.1.4

@ericsvendsen
Copy link
Author

@rajathms unfortunately no. I have noticed that this only happens when the control is initialized. Once you select a date, then all behaves as expected. There's obviously still a bug here but I don't know why it only happens on init. This behavior is in the codepen I posted above.

Regardless, I ended up just creating my own Angular datepicker control since I develop a lot of apps that rely solely on UTC.

@jaybee7

This comment has been minimized.

@rajathms
Copy link

@jaybee7 hello, i took some inputs from @ericsvendsen

A small hack worked for me, i went and comment one line in angular-material.js ( this.focusAfterAppend.focus(); )
under this function

/** Generate and append the content for this month to the directive element. */
 CalendarMonthBodyCtrl.prototype.generateContent = function() {
   var date = this.dateUtil.incrementMonths(this.calendarCtrl.firstRenderableDate, this.offset);

   this.$element
     .empty()
     .append(this.buildCalendarForMonth(date));

   if (this.focusAfterAppend) {
     this.focusAfterAppend.classList.add(this.calendarCtrl.FOCUSED_DATE_CLASS);
     // this.focusAfterAppend.focus();
     this.focusAfterAppend = null;
   }
 };

which worked for me, but i don't suggest you to do the same
I'm waiting for community to fix this bug.
Thank you.

@SocVi100

This comment has been minimized.

@Splaktar Splaktar changed the title md-datepicker highlights wrong date with timezone and initialized model md-datepicker: panel highlights wrong date with timezone and initialized model Jan 5, 2018
@Splaktar Splaktar self-assigned this Jan 5, 2018
@Splaktar Splaktar added this to the 1.1.6 milestone Jan 5, 2018
@Splaktar Splaktar added i18n: localization This issue is related to internationalization P2: required Issues that must be fixed. type: bug labels Jan 5, 2018
@Splaktar

This comment has been minimized.

@Splaktar

This comment has been minimized.

@Splaktar
Copy link
Contributor

Splaktar commented Jan 5, 2018

I have a CodePen with 1.1.1 and it shows that both the datepicker's input and panel show the wrong date.

In my 1.1.5 CodePen the input displays the proper date (taking into account ng-model-options="{ timezone: 'utc' }"), but the datepicker panel does not account for the ng-model-options="{ timezone: 'utc' }" and shows the wrong date.

So this isn't a regression, it's just that the last enhancement didn't quite go far enough.

@Splaktar Splaktar removed this from the 1.1.6 milestone Jan 5, 2018
@Splaktar
Copy link
Contributor

Splaktar commented Jan 5, 2018

After looking at #9410 and https://github.com/angular/material/blob/master/src/components/datepicker/js/datepickerDirective.js a bit more, it looks like this is just a side effect of #10431.

That issue will need to be fixed first, then https://github.com/angular/material/blob/master/src/components/datepicker/js/datepickerDirective.js#L107-L121 can be updated to pass the ng-model-options into the md-calendar.

@Splaktar Splaktar changed the title md-datepicker: panel highlights wrong date with timezone and initialized model md-datepicker: md-calendar panel should respect ng-model-options Jan 5, 2018
@Splaktar Splaktar added Blocked Progress on this issue is blocked. Primarily used for PRs that are blocked by presubmit feedback. type: enhancement and removed type: bug labels Jan 5, 2018
@Splaktar Splaktar added this to the 1.2.0 milestone Jan 5, 2018
@gilad905
Copy link

gilad905 commented Jan 30, 2018

Not the exact behavior of the original post, but pretty close:
https://codepen.io/gilad905/pen/BYywbR

When selecting a date, date is set to one day before the selection.
The earliest version I found where this reproduces is v1.1.2, v1.1.1 is OK.

@Splaktar Splaktar added this to the 1.1.11 milestone Jun 19, 2018
@Splaktar Splaktar modified the milestones: 1.1.11, 1.1.12 Sep 10, 2018
@Splaktar Splaktar modified the milestones: 1.1.12, 1.1.13 Jan 3, 2019
@Splaktar Splaktar modified the milestones: 1.1.13, 1.1.14 Feb 10, 2019
@Splaktar Splaktar modified the milestones: 1.1.14, g3: sync Feb 15, 2019
@Splaktar Splaktar modified the milestones: g3: sync, 1.1.23 Apr 30, 2020
@Splaktar Splaktar changed the title md-datepicker: md-calendar panel should respect ng-model-options datepicker: md-calendar panel should respect ng-model-options May 5, 2020
@Splaktar Splaktar removed the Blocked Progress on this issue is blocked. Primarily used for PRs that are blocked by presubmit feedback. label Jun 8, 2020
@Splaktar
Copy link
Contributor

Splaktar commented Jun 8, 2020

This is no longer blocked, but we need to fix #11919 before digging into this.

@Splaktar Splaktar modified the milestones: 1.1.23, 1.2.0 Jun 19, 2020
@Splaktar Splaktar modified the milestones: 1.2.0, 1.1.24 Jun 29, 2020
Splaktar added a commit that referenced this issue Jun 29, 2020
- pass datepicker's `ng-model-options` on to its calendar

Fixes #11945. Fixes #10598.
@Splaktar Splaktar added the has: Pull Request A PR has been created to address this issue label Jun 29, 2020
Splaktar added a commit that referenced this issue Jun 29, 2020
- fix case where datepicker's model is initially out of sync
  with the input value
- pass datepicker's `ng-model-options` on to its calendar

Fixes #11945. Fixes #10598.
Splaktar added a commit that referenced this issue Jun 29, 2020
- fix case where datepicker's model is initially out of sync
  with the input value
- add demo for `ng-model-options` timezone support
- pass datepicker's `ng-model-options` on to its calendar

Fixes #11945. Fixes #10598.
Splaktar added a commit that referenced this issue Jun 29, 2020
- fix case where datepicker's model is initially out of sync
  with the input value
- add demo for `ng-model-options` timezone support
- pass datepicker's `ng-model-options` on to its calendar

Fixes #11945. Fixes #10598.
Splaktar added a commit that referenced this issue Jun 29, 2020
- fix case where datepicker's model is initially out of sync
  with the input value
- add demo for `ng-model-options` timezone support
- pass datepicker's `ng-model-options` on to its calendar

Fixes #11945. Fixes #10598.
@Splaktar
Copy link
Contributor

This is fixed in master. Please try out the fix (before we release it) via npm install http://github.com/angular/bower-material#master --save or updating your package.json with "angular-material": "git+ssh://git@github.com/angular/bower-material.git#master",.

If you find any issues, please report them via GitHub issues ASAP.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
has: Pull Request A PR has been created to address this issue i18n: localization This issue is related to internationalization P2: required Issues that must be fixed. type: enhancement
Projects
None yet
6 participants