Debian Codegraph @

tools/time_tools.go

raw symbols SCIP
1 package tools
2
3 import (
4 "time"
5 )
6
7 // IsExpiredAtOrIn returns whether or not the result of calling TimeAtOrIn is
8 // "expired" within "until" units of time from now.
9 func IsExpiredAtOrIn(from time.Time, until time.Duration, at time.Time, in time.Duration) (time.Time, bool) {
10 expiration := TimeAtOrIn(from, at, in)
11 if expiration.IsZero() {
12 return expiration, false
13 }
14
15 return expiration, expiration.Before(time.Now().Add(until))
16 }
17
18 // TimeAtOrIn returns either "at", or the "in" duration added to the current
19 // time. TimeAtOrIn prefers to add a duration rather than return the "at"
20 // parameter.
21 func TimeAtOrIn(from, at time.Time, in time.Duration) time.Time {
22 if in == 0 {
23 return at
24 }
25 return from.Add(in)
26 }