2017-04-05 19:57:57 +00:00
|
|
|
package tools
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
2017-04-05 19:58:23 +00:00
|
|
|
// IsExpiredAtOrIn returns whether or not the result of calling TimeAtOrIn is
|
|
|
|
// "expired" within "until" units of time from now.
|
|
|
|
func IsExpiredAtOrIn(until time.Duration, at time.Time, in time.Duration) (time.Time, bool) {
|
|
|
|
expiration := TimeAtOrIn(at, in)
|
|
|
|
if expiration.IsZero() {
|
|
|
|
return expiration, false
|
|
|
|
}
|
|
|
|
|
|
|
|
return expiration, expiration.Before(time.Now().Add(until))
|
|
|
|
}
|
|
|
|
|
2017-04-05 19:57:57 +00:00
|
|
|
// 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)
|
|
|
|
}
|