Aaahh, that makes total sense, thank you so much! On Fri, Nov 11, 2016, 11:59 PM Jakob Borg <ja...@nym.se> 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, much earlier, reference > time. The remainder in that division will be different. > > //jb > > On 11 Nov 2016, at 15:53, Brian Picciano <mediocregop...@gmail.com> wrote: > > 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) > } > > For t2 I'm dividing the unix nano timestamp by the truncation, then > multiplying by the truncation, effectively just removing the remainder. I > would expect that this is what Truncate is doing as well, but this > assertion fails by a couple milliseconds each time. > > --- FAIL: TestWat (0.00s) > tpart_test.go:23: trunc: 947779410 > Error Trace: tpart_test.go:29 > Error: Not equal: time.Time{sec:63614472718, > nsec:711160820, loc:(*time.Location)(0x7bb700)} (expected) > != time.Time{sec:63614472719, > nsec:157822750, loc:(*time.Location)(0x7bb700)} (actual) > > Diff: > --- Expected > +++ Actual > @@ -1,2 +1,2 @@ > -(time.Time) 2016-11-11 07:51:58.71116082 -0700 MST > +(time.Time) 2016-11-11 07:51:59.15782275 -0700 MST > > > Does anyone know what accounts for this difference? NOTE I'm not saying > this is a bug with Truncate, I'm just wondering what all Truncate is doing > that I'm not expecting it to be doing. Thanks! > > -- > > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > > > For more options, visit https://groups.google.com/d/optout. > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.