Skip to content
Browse files

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:


Fixes #14595

Change-Id: I87998a924b11d4dad5512e010b29d2da6b123456
Run-TryBot: Brad Fitzpatrick <>
TryBot-Result: Gobot Gobot <>
Reviewed-by: Andrew Gerrand <>
  • Loading branch information
SamWhited authored and bradfitz committed Aug 30, 2016
1 parent 9f8335b commit 67ea710792eabdae1182e2bf4845f512136cccce
Showing with 6 additions and 0 deletions.
  1. +6 −0 src/time/time.go
@@ -640,6 +640,12 @@ func Since(t Time) Duration {
return Now().Sub(t)

// Until returns the duration until t.
// It is shorthand for t.Sub(time.Now()).
func Until(t Time) Duration {
return t.Sub(Now())

// AddDate returns the time corresponding to adding the
// given number of years, months, and days to t.
// For example, AddDate(-1, 2, 3) applied to January 1, 2011

0 comments on commit 67ea710

Please sign in to comment.
You can’t perform that action at this time.