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

math bug? #4

Open
sneak opened this issue Sep 22, 2020 · 1 comment
Open

math bug? #4

sneak opened this issue Sep 22, 2020 · 1 comment

Comments

@sneak
Copy link

sneak commented Sep 22, 2020

I added a test, I think the calculation you're using is incorrect?

func FromUnixMilli(ms int64) time.Time {
	return time.Unix(ms/int64(millisInSecond), (ms%int64(millisInSecond))*int64(nsInSecond))
}

I don't think you get the integer nanoseconds portion by doing (ms%int64(millisInSecond))*int64(nsInSecond). I used this and got some incorrect results.

Test (failing) is here:

https://github.com/Tigraine/go-timemilli/pull/3/files

@lss4
Copy link

lss4 commented Nov 17, 2021

Just tried. It's working as intended. That test failed because the timestamp returned by time.Now() has a higher precision.

Though I do agree the name of the const, nsInSecond, is not correct here. It should be nsInMillisecond.

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

2 participants