by ammario on 7/15/24, 6:30 PM with 46 comments
by neild on 7/15/24, 9:05 PM
by playingalong on 7/15/24, 8:26 PM
by elchief on 7/15/24, 8:26 PM
by jamesrr39 on 7/16/24, 5:41 PM
type NowFunc func() time.Time
func getGreeting(nowFunc NowFunc) string {
now := nowFunc()
if now.Hour() < 12 {
return "Good Morning"
}
return "Good day"
}And just pass in `time.Now` in for live code, and your own inline function for simulating a time in tests.
by alpb on 7/16/24, 1:58 AM
by nsguy on 7/15/24, 10:05 PM
It's quite tricky is sort of the bottom line. It's not enough to just create fake time there's a lot more to it.
by rmetzler on 7/16/24, 7:03 AM
by wolfspaw on 7/15/24, 9:23 PM
by wizzard0 on 7/15/24, 7:46 PM