go-tools: staticcheck: Report incorrect equality checks of time.Time values.

Package time documents that:

Do not use == with Time values.

(Source: https://godoc.org/time#Time.Equal.)

This probably extends to != for inequality checks too.

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Comments: 15 (14 by maintainers)

Most upvoted comments

Reopening under the aggressive label, for a future set of checks specific to code review.

Then Time values can’t be used at all in comparable types, for example when used as map keys at some level.

What makes you say that?

Read the entire paragraph I quoted in https://github.com/dominikh/go-tools/issues/47#issuecomment-283490396, it pretty much says explicitly that you can use time.Time values as map keys, provided you perform the neccessary actions to make == operator work as expected (and there are extra considerations in Go 1.9 compared to 1.8).

Anyway, I’m tracking dealing with this issue upstream at https://github.com/shurcooL/backlog/issues/31.

I’ve used == in the past with times I have called UTC() on, so I’m inclined to believe this would be too strict.