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

Invoking endOf('day') multiple times #327

Closed
marcomarasca opened this issue Apr 5, 2016 · 2 comments
Closed

Invoking endOf('day') multiple times #327

marcomarasca opened this issue Apr 5, 2016 · 2 comments
Labels

Comments

@marcomarasca
Copy link

marcomarasca commented Apr 5, 2016

I think I may have found an issue: if I invoke the endOf('day') multiple times I would expect the date to remain the same, but apparently this is not the case during (some) DST transitions:

moment.tz.setDefault('Europe/Rome');
var date = moment('1979-05-27', 'YYYY-M-D').endOf('day'); 
date.valueOf() // 296693999999
date.endOf('day').valueOf(); // 296776799999

Did I get something wrong? In this very case it actually goes to the end of the following day. It does not seem to happen with dates after the 1979.

@mattjohnsonpint
Copy link
Contributor

Well, there's a transition in this time zone on this day at midnight. 1979-05-27T00:00:00+01:00 => 1979-05-27T01:00:00+02:00. See here also.

However, there still looks to be a bug. It's more clearly demonstrated this way:

var m = moment.tz('1979-05-27', 'YYYY-M-D', 'Europe/Rome');
m.format();  // "1979-05-27T01:00:00+02:00"   (correct)
m.endOf('day');
m.format(); // "1979-05-28T00:59:59+02:00"  (incorrect, should be "1979-05-27T23:59:59+02:00")

This appears to be due to the implementation of endOf in moment. To calculate the end of the day, it does the start of the day, plus one day, less one millisecond. That logic fails when the day doesn't start at midnight. I'll log this in the moment issue tracker, as it needs to be fixed there.

@mattjohnsonpint
Copy link
Contributor

We'll track in moment/moment#3132. Thanks for reporting.

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

No branches or pull requests

2 participants