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

Day of Year breaks due to Daylight savings #101

Open
tainegilliam opened this issue Dec 17, 2020 · 0 comments
Open

Day of Year breaks due to Daylight savings #101

tainegilliam opened this issue Dec 17, 2020 · 0 comments

Comments

@tainegilliam
Copy link

Your Day Of Year Native code will fail between midnight and 1am during daylight savings.

My replacement was:

Math.floor( (new Date().setHours(2) - new Date(new Date().getFullYear(), 0, 0)) / 1000 / 60 / 60 / 24 );

which forces the time for the day.

Alternatively:

Math.floor( (Date.UTC(year, month, day) - Date.UTC(year, 0, 0)) / 1000 / 60 / 60 / 24 )

The opposite code is quite simple, too:

new Date(year, 0 , dayOfYear)

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

No branches or pull requests

1 participant