According to https://golang.org/pkg/time/#Duration.Round "If m <= 0, Round 
returns d unchanged". So now I'm really curious, why do the Round() at all?

s

On Sunday, April 19, 2020 at 6:45:45 PM UTC-7, ise...@gmail.com wrote:
>
> Hi,
>
> I have been looking at various packages to understand how one goes about 
> implementing things in Go. I have been learning a great deal just by 
> getting my head around code written by smarter devs than I'm ever likely to 
> be ;)
>
> Whilst looking at golang/oauth2, two lines of code handling token expiry 
> led me to discover about time.Time's use of both wall and monotonic clocks. 
> I realised that either I had failed to understand something or the code was 
> wrong. I'm assuming it's the former, so hopefully somebody can explain it 
> to me...
>
> In oauth2/internal/token.go, doTokenRoudnTrip sets the Token.Expiry as 
> follows:
>
> token.Expiry = time.Now().Add(time.Duration(expires) * time.Second)
>  
> In oauth2/token.go, the Token.expired function returns this:
>
> return t.Expiry.Round(0).Add(-expiryDelta).Before(timeNow())
>
> If I have read the time package documentation correctly, the monotonic 
> clock reading is intended for time measurements. In particular, it provides 
> robust behaviour for functions such as Before().
>
> So I do not understand why the monotonic reading is stripped from the time 
> value with Round(0) before invoking Before() in the code above. As I read 
> it, the token.Expiry has a monotonic clock reading (now + duration) which 
> is then stripped when evaluated against Before(now) later on... does this 
> not make the code susceptible to issues when system time is being adjusted? 
> What is the rationale for Round(0) in this case?
>
> -- ise
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/a4167638-c04a-4e64-9374-67fe240135c4%40googlegroups.com.

Reply via email to