tools/time: introduce TimeAtOrIn to calculate absolute time from optional relative

This commit is contained in:
Taylor Blau 2017-04-05 13:57:57 -06:00
parent dc0b3c60ad
commit 24fea8fc61

13
tools/time_tools.go Normal file

@ -0,0 +1,13 @@
package tools
import "time"
// TimeAtOrIn returns either "at", or the "in" duration added to the current
// time. TimeAtOrIn prefers to add a duration rather than return the "at"
// parameter.
func TimeAtOrIn(at time.Time, in time.Duration) time.Time {
if in == 0 {
return at
}
return time.Now().Add(in)
}