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

Fixes incorrect dates from parsed values #24

Merged
merged 2 commits into from
Jul 9, 2017
Merged

Conversation

maxf
Copy link
Contributor

@maxf maxf commented Jun 1, 2017

Closes #23

Using new date() returns the current system date. Modifying the date afterwards can have unexpected consequences if the system's date is the 31st. For instance, parsing 2015-09-12

var date = new Date()  # date is set to system date (2017-05-31, for instance) 
date.setUTCFullYear(dateParts[0]); # date is now 2015-05-31 
date.setUTCMonth(dateParts[1] - 1); # date is now 2015-10-01, because 2015-09-31 is not a valid date
date.setUTCDate(dateParts[2]); # date is now 2015-10-12

The resulting date is one month ahead of what was parsed.

Writing a regression test is difficult as it would necessitate setting the system date.

Max Froumentin added 2 commits June 2, 2017 00:27
Otherwise the resulting date isn't always correct.
Closes bwindels#23
@bwindels
Copy link
Owner

bwindels commented Jul 9, 2017

Look good, thanks for the fix!

@bwindels bwindels merged commit f075a79 into bwindels:master Jul 9, 2017
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.

None yet

2 participants