angular-calendar icon indicating copy to clipboard operation
angular-calendar copied to clipboard

Wrong dates using moment time zone with angular calendar

Open rmonteroh opened this issue 2 years ago • 5 comments

Describe the bug I am using an angular calendar with moment js and when defining the default time zone of moment moment.tz.setDefault('America/New_York'); in some cases I get the calendar with the wrong dates and it even starts on Saturday when it should start on Sunday

Minimal reproduction of the problem with instructions Define a different time zone for moment than the one you have locally, ex moment.tz.setDefault('America/New_York');

Screenshots image

Versions

  • @angular/core: 12.0.5
  • angular-calendar: ^0.28.22
  • Browser name and version: Chrome, safari

rmonteroh avatar Feb 03 '22 05:02 rmonteroh

Thanks so much for opening an issue! If you'd like me to give priority to answering your issue or would just like to support this project, then please consider sponsoring me

matts-bot[bot] avatar Feb 03 '22 05:02 matts-bot[bot]

I have the same issue. Moreover, in the week view the start time changes. If my time zone is +1, then it starts from 11pm instead of 12am

ghidoz avatar Feb 24 '22 13:02 ghidoz

I fix this issue by moving the providers from the parent component module to the child component module providers: [ { provide: CalendarDateFormatter, useClass: CalendarMomentDateFormatter, }, ],

rmonteroh avatar Feb 24 '22 14:02 rmonteroh

Thanks @rmonteroh, you actually pointed me to the solution! My custom CalendarDateFormatter was using the Angular formatDate, while I had to change it using moment.

So like:

import * as moment from 'moment-timezone';

public dayViewHour({ date, locale }: DateFormatterParams): string {
    return moment(date).format('HH:mm');
}

Now the calendar displays the right day and it always starts from 00:00, no matter the computer timezone

ghidoz avatar Feb 28 '22 10:02 ghidoz

Just ran into the same issue and @ghidoz 's solution was what fixed it for me.

So, I don't think this is a bug, but the example for making custom date adaptors should have some sort of warning that this sort of thing is possible and that you need to use the moment version instead of the standard one if using moment elsewhere.

JaxonWright avatar Mar 29 '22 19:03 JaxonWright