tools/time: introduce TimeAtOrIn to calculate absolute time from optional relative
This commit is contained in:
parent
dc0b3c60ad
commit
24fea8fc61
13
tools/time_tools.go
Normal file
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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user