Re: [go-nuts] time.Truncate output is _slightly_ different than expected

2016-11-12 Thread Brian Picciano
Aaahh, that makes total sense, thank you so much! On Fri, Nov 11, 2016, 11:59 PM Jakob Borg wrote: > You are dividing the number of nanoseconds since the Unix epoch by some > random number of nanoseconds and chopping off the remainder. But a > time.Time internally is an interval since another, m

Re: [go-nuts] time.Truncate output is _slightly_ different than expected

2016-11-11 Thread Jakob Borg
You are dividing the number of nanoseconds since the Unix epoch by some random number of nanoseconds and chopping off the remainder. But a time.Time internally is an interval since another, much earlier, reference time. The remainder in that division will be different. //jb > On 11 Nov 2016,

[go-nuts] time.Truncate output is _slightly_ different than expected

2016-11-11 Thread Brian Picciano
Here's a test case to show what I mean: func TestWat(t *T) { now := time.Now() trunc := rand.Int63n(int64(time.Second)) t.Logf("trunc: %v", trunc) t1 := now.Truncate(time.Duration(trunc)) t2 := time.Unix(0, trunc*(now.UnixNano()/trunc)) // this fails for some reason assert.Equal(t, t1, t2) } Fo