Skip to content
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

Daylight savings time does not seem to be handled correctly. #146

Open
tchari opened this issue Apr 30, 2018 · 4 comments
Open

Daylight savings time does not seem to be handled correctly. #146

tchari opened this issue Apr 30, 2018 · 4 comments

Comments

@tchari
Copy link

tchari commented Apr 30, 2018

When creating a new moment at hour when daylight savings changes, Moment returns an invalid date error. Moment.js, on the other hand, returns the changed hour. For example:
$date = new Moment('2017-03-12 02:00:00', 'America/Edmonton);
return an invalid date. However, in moment.js
var now = moment('2017-03-12 02:00:00').format('MMM DD h:mm A');
returns "Mar 12 3:00 AM"

I believe the isValid() is unable to handle the daylight savings hour case.

@hriziya
Copy link

hriziya commented Mar 5, 2019

I wanted to use this library for my ongoing project but I am unsure on how this will handle the DST?

@tchari
Copy link
Author

tchari commented Mar 5, 2019

For my use case I was taking as input a date time string (e.g. 2018-04-05 15:00:00) and a time zone separately. I had to create a native DateTime and DateTimeZone object first and then create my Moment from the DateTime because the native class correctly handles DLS.

@hriziya
Copy link

hriziya commented Mar 5, 2019

I agree, but I am still not sure if creating the native DateTime and DateTimeZone would work..

here is the small sample I am worried about.
I am trying to convert America/Chicago time to UTC to store in database. but you can see that when I try to consider Timezone Name and Timezone Offset the output are different event with native DateTimeZone object. so I doubt Moment could handle this. This may not be the DST issue. but something related to it.
sample
Any clue on this?

@tchari
Copy link
Author

tchari commented Dec 16, 2020

@hriziya
Super late on this reply; sorry

I don't think using the offset strategy vs. a named timezone is really comparable because there are a lot of different timezones that the same offset.

For example, lets say you were using a an offset of -7. In the summer months that offset corresponds to America/Whitehorse, America/Vancouver, America/Los_Angeles, among others. In the winter months, that offset corresponds to America/Whitehorse, America/Edmonton, America/Denver, etc.

If you're using a fixed offset would not expect DLS to ever really be handled appropriately because DLS is a jurisdiction-by-jurisdiction thing. I think if you use the named timezone, native PHP's DateTime and DateTimeZone classes should handle it properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants