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

Bug: time manipulation is incorrect when crossing DST #465

Closed
destroytoday opened this issue Mar 19, 2017 · 3 comments
Closed

Bug: time manipulation is incorrect when crossing DST #465

destroytoday opened this issue Mar 19, 2017 · 3 comments
Assignees
Labels

Comments

@destroytoday
Copy link

Because time manipulation methods like addHours use set methods like setHours, crossing DST results in unexpected times.

Example:
In New York, DST starts on March 12 at 2am, skipping the hour between 2am and 3am. If you add 3 hours to the start of the day, it should return 4am (midnight + 3 hours, skipping 2am). date-fns returns 3am because it calls setHours(3).

Solution:
Instead of using setHours, date-fns should add milliseconds to the given Date object:
new Date(date.getTime() + hours * 3600000)

@gscottolson
Copy link

👍

@leshakoss
Copy link
Contributor

@destroytoday @gscottolson released the addMilliseconds, addSeconds, addMinutes, addHours, subMilliseconds, subSeconds, subMinutes and subHours fix in v1.28.1 (diff: v1.28.0...v1.28.1)

@binury
Copy link

binury commented Nov 6, 2019

This seems to still be an issue (off-by-1) when using addDays & subDays

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

5 participants