From: Sam Whited Date: Wed, 2 Mar 2016 06:00:23 +0000 (-0600) Subject: time: Add Until helper function X-Git-Tag: go1.8beta1~1582 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=67ea710792eabdae1182e2bf4845f512136cccce;p=gostls13.git 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 TryBot-Result: Gobot Gobot Reviewed-by: Andrew Gerrand --- diff --git a/src/time/time.go b/src/time/time.go index c31de357d5..a6e100fa71 100644 --- a/src/time/time.go +++ b/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