-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Day incorrect in datepicker #7167
Comments
Could you try to reproduce it here, please: https://plnkr.co/edit/8nRKSJ?p=preview ? |
I just want that the date I have selected in calendar is already in UTC timezone |
The calendar returns a javascript Date object. What you've shown in above message seems like something generated from other source (it looks like a JSON.stringify() result or maybe from a database service). To get back the Javascript Date object, you have to do (really not sure how did you get that result): fareCalendar.startDate = new Date(fareCalendar.startDate); |
If I select th date: 6/9/2017 and print it I see: Then I save the date in a body |
Yes, I want the date selected is already UTC, I used primeng calendar and there is a property like utc="true" that solve this. |
Well... I really don't know if it's planned to support such a utc attribute. cc: @mmalerba |
We do plan to add support for different timezones/offsets, but its not there yet. In the mean time you could make a custom Here is the Some examples of existing implementations: And some documentation that may help: |
@lippomano I have the same request. Did you get any solution about it ? thank you for any suggestions. |
@we125182 I write a method that manipulate every date it is not the best practice but it's simpler for me |
I get this exact same behaviour on https://material.angular.io/components/datepicker/overview |
@adaojunior if you're seeing the same issue on the docs site its likely some issue related to your locale / time zone. Any additional information you can provide would be useful. If you're using Moment.js in your app (or willing to try it) you could give the |
@mmalerba same issue on the docs, see: I'm using |
@mmalerba Hello, is it possible to import MatMomentDateModule from @angular/material-moment-adapter when using beta12? I cannot find the way to do it, it's seems to me this module is not yet released? |
@npen yeah I think it missed the release, you can install it from here in the mean time: https://github.com/angular/material2-moment-adapter-builds |
Adding +1 day is a new "feature" with the day picker whilst using the default DateAdapter. I believe it has been introduced in beta 12. This also happens for me on the material angular site: Today is the 12th of October at 22:30. To replicate:
I'm using an Aussie time zone. 22:30. When I switch back to Europe, it works as intended despite being on the same day as in Australia. |
@jt-helsinki Thanks for the detailed info, strangely I am unable to reproduce it using the same settings. I tried 12th of October 2017 at 22:30 in the following time zones (all of the Australian ones listed on my system): Adelaide, Brisbane, Broken Hill, Currie, Darwin, Ecula, Hobart, Lindeman, Lord Howe, Melbourne, Perth, Sydney. All of them showed the 12th circled and selected the 12th after clicking (on docs site) If anyone knows what I'm doing wrong please let me know... |
Looks like you're doing exactly what I was doing. I notice I'm on a different OS. An unlikely shot, could it be a OS/browser thing? I'm on: Anyone else care to confirm? The strange thing with this is that the date had not yet flipped to the following day. Europe and Australia were still on the same day. |
@jt-helsinki @adaojunior, are you in regions with daylight saving time period currently on? |
Yes!! Sydney!! |
And is it a normal DST period, I mean, every year, in October, Sydney is usually in DST...? |
yes, First weekend of Oct to first weekend of April of the next year |
@mmalerba, I've heard of something about ECMA 5.1 and previous versions having DST issues... if this is the problem, it would affect older browsers (that, for sure, is not the case of @jt-helsinki's #7167 (comment)). Look at this test in IE 11 that I couldn't reproduce in Chrome (I think you have already noticed the calendar showing the 31st day of the previous month): In above image, automatic DST detection is activated. If I disable it the problem doesn't happen. EDIT: take a look at this old article that I've found: https://codeofmatt.com/2013/06/07/javascript-date-type-is-horribly-broken/ Maybe some polyfills are causing the problem. |
Oddly enough, this started happening when the Aussie daylight savings time ticked over. Strange because he same problem doesn't happen here in Europe. Then again, maybe it will when the clocks change at the end of the month. |
@jt-helsinki , same thing here in Europe when DST kicked in. If DatePicker is not supposed to handle different timezones, shouldn't it ( at least ) handle DST ? |
Indeed it should, hence the open PR to fix it |
@mmalerba shouldnt the datepicker not support timezones its for selecting only date if i am selecting date of birthday it shouldnt change according to different time zones |
I made my self a workaround by overriding the MomentJS DateAdapter compiling the date from UTC and then converting it into the locale date:
The important line being:
|
@Silthus |
Silthus' workaround works great. @mmalerba: Is there a plan to implement something into oficial MomentDateAdapter to avoid workarounds? |
@MichalK6677 I wasn't aware that the |
@mmalerba I can send a PR later this day. |
Moment DateAdapter should create dates in utc format to avoid time zone collisions when passing date to servers Closes angular#7167
Added MAT_MOMENT_DATE_ADAPTER_OPTIONS with the useUtc: boolean option to parse dates as utc The new option defaults to false and will not cause any breaking changes. Closes angular#7167
Describe how to set the MomentDateAdapter to parse dates as utc. Describe the default behaviour of the MomentDateAdapter. Add an example on how to configure MAT_MOMENT_DATA_ADAPTER_OPTIONS Closes angular#7167
You can change the default behaviour to parse dates as UTC by providing the MAT_MOMENT_DATA_ADAPTER_OPTIONS and setting it to useUtc: true. @NgModule({ Check here for more details |
However, this..., it's not should, it must be default configuration for datepicker. |
Why does datepicker care about the timezones at all? Who would ever need that? |
@raibait, in fact, it doesn't care about it. But the underlying objects that currently store the date values usually do (regular javascript Date objects and Moment.js are the most common cases). This is the reason for so many issues related to wrong dates. Building a date adapter and configuring it correctly is important to avoid headaches. |
Maybe the problem here is the fact that the datepicker's Of course, I can fix all this by writing my own date adapter, or going out and getting the Moment-based one, but as long as the default behavior is Date-based, you're going to keep seeing people showing up in this thread. |
thanks, it's work very well :) |
@Silthus the adapter you did works like a charm, but I have a requirement to set the format for the date. my date format: "DD MMM YYYY" // 15 jul 2019 |
I am wondering if adding the When using the Honolulu timezone (spoofing the browser), we were not able to make moment work, we ended up having to manually remove the timezone offset in order to get the mat-datepicker to choose the correct date:
When I tried to get it to work with moment it cause a whole host of other issues. However this still causes the selection to be wrong: Not looking for a solution, just alerting to the issues |
Stackblitz showing crazy go nuts wonky-ness when you have your browser spoofed to India time: https://stackblitz.com/edit/angular-trude-datetest And in that stack blitz, look at what it selects in the UI: So set to the 6th, moment converts to the 5th, mat-datepicker displays the 4th, but selects the 3rd. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug, feature request, or proposal:
When I select a date I see the correct date in the field but, when I save, the datepicker send the day before the date I have selected
here's the code:
<md-form-field> <input mdInput [(ngModel)]="fareCalendar.startDate" name="startDate" [mdDatepicker]="picker" placeholder="startDate"> <md-datepicker-toggle mdSuffix [for]="picker"></md-datepicker-toggle> <md-datepicker #picker></md-datepicker> </md-form-field>
I am using angular 4 and @angular/material": "^2.0.0-beta.10
but the date:
How can I send the UTC date
The text was updated successfully, but these errors were encountered: