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

Convert UTC time to local time; Close #90 #103

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

Conversation

JacobDB
Copy link

@JacobDB JacobDB commented Jan 8, 2018

Implemented @nandaleite's solution to issue #90. Tested in Node v6 and in v8, it's working fine in both instances.

@JacobDB
Copy link
Author

JacobDB commented Jan 9, 2018

Tested in Node v9 today, no issues there either.

@morris
Copy link
Owner

morris commented Jan 27, 2018

Could you add tests to verify this works? I'm unsure if the date arithmetic will work. getHours() - 1 especially has a few edge cases. Thanks!

@JacobDB
Copy link
Author

JacobDB commented Feb 12, 2018

Unfortunately, I'm really not much of an expert when it comes to Node JS development; if you can point me in the right direction I'd be happy to add some tests, I'm just not sure where to even start with something like that.

@arktds
Copy link

arktds commented Feb 19, 2019

As far as I see, this works seems good.
If date.getTimezoneOffset() returns 60 in UTC+1, then var timezone = date.getTimezoneOffset() / 60 // = 1.
Even in this case, obj.date = date.setHours(date.getHours() - timezone); should works properly.

@morris
Copy link
Owner

morris commented May 3, 2019

What happens for date.getHours() === 0? Then obj.date = date.setHours(-1)? If you can provide a test I'd be happy to merge :)

@urosg80
Copy link

urosg80 commented Dec 27, 2019

According to documentation this ensures that the date is also changed - i.e. last hour of previous day; also in posted example it is shown how to "move" time 48 hours back (in the example).

Actually after testing this I found out that this fix doesn't work correctly.

The correct way to set UTC time (as local stat times are also in UTC) is not to mess with timezoneoffset and sethour etc. at all. Just include "+00:00" at the end of the date/time string when composing the new Date object.

#127 fixes this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants