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
Fix handling of DST jumps in Brazilian timezones in startOf/endOf #4164
Conversation
1c2ad41
to
47b853a
Compare
Tagging @mj1856 as the most likely person to be able to shepherd this along. |
@Seldaek can you explain which case are you fixing (not "brazillian" but put more technical perspective). Also I'm a bit against doing twice the work in |
@ichernev The case is that some timezones (Brazil/Sao_Paolo is one) switch DST at midnight, which means that midnight does not exist but it switches from 23:59:59 to 01:00:00 on the DST switch date. Due to this, and some different ways Firefox and Chrome handle dates, momentjs ends up jumping to the wrong date when using startOf/endOf. The problem is also present when doing things like adding an hour if you are at 23:00:00 of course, but that's less common and way harder to fix, so it is not in the scope here. I don't know exactly what else you want, the PR description and jsfiddle have a lot of info already. |
I made a PR too, didn't saw this one. The one I did solves just the problem of daylight saving time. |
Seems like the problem is fixed in current version. @Seldaek |
This problem still persists in current version. |
@ichernev anything I can do to help get this in? We've been running with it in production since september without any issues. |
@marwahaha I realistically won't have the time to check for this next few weeks so I'd say if you think it's good go ahead and merge it, once it's in a release I will try and migrate our codebase back to mainline moment see if things still work |
@marwahaha #4338 doesn't fix that. |
With our code (https://github.com/Seldaek/moment/commits/integration) I get this: With CET timezone:
Then I switched to Brasilia timezone:
Seems fixed to me.. |
@Seldaek the integration branch is ok. The GH3132 is not. edit: misspelling |
Did you build momentjs though? If you just check out the branch without building then you're not getting any of the fixes. |
I don't. Sorry. I just pointed my package.json to the git branch. |
@marwahaha I'm sorry for that. As the @Seldaek has mentioned, I forgot the build it. The #4338 solves this issue. |
closing in favor of #4338 |
Fixes #3132
The approach taken here is a bit different than previous ideas (e.g. #3716) where startOf was called twice in endOf. Here we apply endOf much like startOf is done, so that startOf does not have to be called in endOf. Then in startOf it also checks for DST failures where some browsers return the previous or next day when they are set to a midnight that does not exist due to the DST jump. This is handled only for those time units which require it to avoid performance issues, but overall the performance impact should be very low as it only does a couple extra comparison in most cases.
The patch is demonstrated in https://jsfiddle.net/1gpr1fys/7/ in case you want to play with it and do your own tests. It logs all
true
in the console if you have the correct timezone (Brazil/Sao Paulo or Brasilia). Works in both Firefox and Chrome.If you have another timezone that does the DST switch not at midnight, then tests 1 and 4 in the demo fail because they return midnight instead of 1am, that's normal. The test suite of moment though passes as it always mimicks the Brazil timezone in the tests checking for this behavior.