Use time.Until
ID |
go.time_until |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Code Smell |
Language |
Go |
Tags |
code-style, readability |
Description
Reports the call x.Sub(time.Now()) on a time.Time value. The standard library provides
time.Until(x) as a shorthand for the duration from now until x.
Rationale
time.Until(t) is defined as t.Sub(time.Now()), so the explicit form says the same thing with
more words. Preferring time.Until reads better and matches the idiom most Go code uses for
computing the time remaining until a deadline.
func remaining(deadline time.Time) {
d := deadline.Sub(time.Now()) // FLAW — use time.Until(deadline)
_ = d
}