Skip to content

Commit 67ea710

Browse files
SamWhitedbradfitz
authored andcommitted
time: Add Until helper function
Adds an Until() function that returns the duration until the given time. This compliments the existing Since() function and makes writing expressions that have expiration times more readable; for example: <-After(time.Until(connExpires)): Fixes #14595 Change-Id: I87998a924b11d4dad5512e010b29d2da6b123456 Reviewed-on: https://go-review.googlesource.com/20118 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Andrew Gerrand <[email protected]>
1 parent 9f8335b commit 67ea710

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/time/time.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,12 @@ func Since(t Time) Duration {
640640
return Now().Sub(t)
641641
}
642642

643+
// Until returns the duration until t.
644+
// It is shorthand for t.Sub(time.Now()).
645+
func Until(t Time) Duration {
646+
return t.Sub(Now())
647+
}
648+
643649
// AddDate returns the time corresponding to adding the
644650
// given number of years, months, and days to t.
645651
// For example, AddDate(-1, 2, 3) applied to January 1, 2011

0 commit comments

Comments
 (0)