Skip to content

report time.Date used with leading zeroes (so the octal notation) #1326

Closed
@ccoVeille

Description

@ccoVeille

Is your feature request related to a problem? Please describe.

time.Date is often used with leading zeroes

time.Date(2023, 01, 02, 03, 04, 05, 06, time.UTC)

This pattern is pretty common as it replicates the natural way a human would write dates.

But the leading zeros that seem OK, forces the value to be octal literals.

This would be the way to define the date,

time.Date(2023, 1, 2, 3, 4, 5, 6, time.UTC)

It doesn't seem to be a real problem, but the following code cannot compile

time.Date(2023, 01, 02, 03, 08, 00, 00, time.UTC)

Here someone wanted to use 08:00:00 UTC time, but 08 is not a valid octal.

So some PR requires to change from octal notation to decimal one to be able to use 08 and 09

There is fortunately no conversion issues for number under 7 (octal range is 0-7)

Also, there is a real concern when gofumpt faces octal notation, it will transform it to this.

time.Date(2023, 0o1, 0o2, 0o3, 0o4, 0o5, 0o6, time.UTC)


This pattern is not that common
, but pretty ugly.

Describe the solution you'd like

A new rule to detect this.

Describe alternatives you've considered

  • updating the code of gofumpt, it's strange to add exception for this in gofumpt code that is very simple
  • adding exception to go-critic octalLiteral, the code is very simple, and the linter is not aware of how an octal is used, so it would require a lot of code change to check if we are in time.Date method

Additional context

I faced this when:

  • I tried to use the time 08:00:00 and wrote time.Date(2023, 01, 02, 03, 08, 00, 00, time.UTC)
  • gofumpt reformated some files

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions