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

fix(timepicker): fix date overflow on short months #6480

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

a-mcc
Copy link

@a-mcc a-mcc commented Jul 7, 2022

Change year, month, date setting on time change to be atomic, preventing overflows for short months.
When the time is decremented before midnight such that the date would go back a day there is code to reset the year, month and day, in that order. this causes an issue with shorter months, for example February or April, when on the 1st of these months and the date goes back a day, calling date.setMonth(monthIndex) causes an overflow to the next month.
For example, February 1st 00:00:00 -> January 31st 23:00:00
Upon calling date.setMonth(1) we are essentially setting the date to February 31st which rolls over a few into March. date.setDate(1) is then called which results in the Date object representing March 1st, instead of February 1st.
The fix is a simple one, date.setFullYear accepts arguments for year, month and day, allowing these to be set atomically and prevents this overflow issue.

Closes #5766

change year, month, date setting on time change to be atomic, preventing overflows for short months

Closes 5766
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

Successfully merging this pull request may close these issues.

Spinning the timepicker down below zero on April 1st moves the date to May 1st
1 participant