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

Unix timestamp is incorrect? #497

Closed
jsumners opened this issue Feb 15, 2019 · 7 comments · Fixed by #517
Closed

Unix timestamp is incorrect? #497

jsumners opened this issue Feb 15, 2019 · 7 comments · Fixed by #517
Labels

Comments

@jsumners
Copy link

if (new Date().getTimezoneOffset() === 0) then dayjs.unix(1550251173).startOf('day').unix() returns 1550188800.

if (new Date().getTimezoneOffset() === 300) then dayjs.unix(1550251173).startOf('day').unix() returns 1550206800.

A Unix timestamp is by definition a count of seconds from "00:00:00 Thursday, 1 January 1970, Coordinated Universal Time (UTC)" (http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_16). Thus, the correct result should always be 1550188800.

@ghost
Copy link

ghost commented Feb 16, 2019

Because in dayjs.unix(1550251173), dayjs parses and displays in local time. The same in momentjs.

@jsumners
Copy link
Author

Yes, that should parse into local time. But the final conversion back to a Unix timestamp should generate a number at UTC.

@ghost
Copy link

ghost commented Feb 16, 2019

Yes, and that will be of course different. Cause startOf('day') is different.

@jsumners
Copy link
Author

What do you not understand? The number that results from dayjsInstance.unix() should be the number of seconds from 00:00:00 Thursday, 1 January 1970 at the UTC timezone.

jsumners added a commit to jsumners/dayjs that referenced this issue Feb 16, 2019
@jsumners
Copy link
Author

I'm closing this until I can figure out where the actual bug lies. I'm not really sure what is happening here.

@iamkun
Copy link
Owner

iamkun commented Mar 6, 2019

try UTC plugin

@iamkun
Copy link
Owner

iamkun commented Mar 6, 2019

🎉 This issue has been resolved in version 1.8.9 🎉

The release is available on:

Your semantic-release bot 📦🚀

@iamkun iamkun added the released label Mar 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants