github.com/leanovate/gopter@v0.2.9/gen/time_shrink.go (about) 1 package gen 2 3 import ( 4 "time" 5 6 "github.com/leanovate/gopter" 7 ) 8 9 // TimeShrinker is a shrinker for time.Time structs 10 func TimeShrinker(v interface{}) gopter.Shrink { 11 t := v.(time.Time) 12 sec := t.Unix() 13 nsec := int64(t.Nanosecond()) 14 secShrink := uint64Shrink{ 15 original: uint64(sec), 16 half: uint64(sec), 17 } 18 nsecShrink := uint64Shrink{ 19 original: uint64(nsec), 20 half: uint64(nsec), 21 } 22 return gopter.Shrink(secShrink.Next).Map(func(v uint64) time.Time { 23 return time.Unix(int64(v), nsec) 24 }).Interleave(gopter.Shrink(nsecShrink.Next).Map(func(v uint64) time.Time { 25 return time.Unix(sec, int64(v)) 26 })) 27 }