-
Notifications
You must be signed in to change notification settings - Fork 18k
time: Round does not work with 7ms. #70449
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
Comments
Related Issues
Related Code Changes (Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
see https://pkg.go.dev/time#Time.Round
Zero time is not unix 0, it's offset by 62135596800000 milliseconds, so division based in unix milliseconds is wrong. Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only. For questions please refer to https://github.com/golang/go/wiki/Questions |
@seankhliao I'm struggling to see how this is not a bug, even with a local tz offset this appears to be a very clearly not intended. If you're confident this isn't a bug I'm happy to jump to Questions, but the smallest unit here is Nanoseconds, and Round still does not work properly with the same defective integers. This one liner also reliably reproduces this at the nanosecond scale: https://go.dev/play/p/bNALNfokU69
https://go.dev/play/p/OwyyQIRhWWl
|
It is not a bug. package main
import (
"fmt"
"time"
)
func main() {
t0 := time.Time{}
t1 := time.Now().Round(7 * time.Millisecond)
unixMilli := t1.UnixMilli()
absMilli := (-t0.UnixMilli()) + unixMilli
fmt.Println(unixMilli % 7) // 4
fmt.Println(absMilli % 7) // 0
} |
This just seems wild. (Now I'm trying to figure out) How do I properly call time.Now() so that Round or Truncate reliably work? https://go.dev/play/p/KxqhNtxQKoH
|
Please take your questions to the forums, Round is working as documented. |
Go version
go1.23.2 windows/amd64
Output of
go env
in your module/workspace:What did you do?
https://go.dev/play/p/Mvbh3SQwa3b
What did you see happen?
7 is broken. not a multiple of 4
7 is broken. failed round count 0
11 is broken. not a multiple of 2
11 is broken. failed round count 0
13 is broken. not a multiple of 4
13 is broken. failed round count 0
14 is broken. not a multiple of 4
14 is broken. failed round count 0
17 is broken. not a multiple of 11
17 is broken. failed round count 0
19 is broken. not a multiple of 18
19 is broken. failed round count 0
21 is broken. not a multiple of 18
21 is broken. failed round count 0
22 is broken. not a multiple of 2
22 is broken. failed round count 0
23 is broken. not a multiple of 11
23 is broken. failed round count 0
26 is broken. not a multiple of 4
26 is broken. failed round count 0
28 is broken. not a multiple of 4
28 is broken. failed round count 0
29 is broken. not a multiple of 3
29 is broken. failed round count 0
31 is broken. not a multiple of 13
31 is broken. failed round count 0
33 is broken. not a multiple of 24
33 is broken. failed round count 0
34 is broken. not a multiple of 28
34 is broken. failed round count 0
35 is broken. not a multiple of 25
35 is broken. failed round count 0
What did you expect to see?
.
Something's not right with the rounding code. 5 and 10 work, but once you start to get up there things fall apart fast.
The text was updated successfully, but these errors were encountered: