Skip to content

proposal: time: Duration String() should omit zero units #39064

@XSAM

Description

@XSAM

What version of Go are you using (go version)?

1.14.2

Proposal

I propose that time.Duration.Strings() should omit zero units.

For example

fmt.Println((5 * time.Hour).String())

With this proposal, this example result will change from 5h0m0s to 5h.

  1. It's more concise. Zero units like 0m0s is meaningless.
  2. Currently, we already omit the ns, µs and ms units if its value is zero, so we should also emit the s and h unit to keep the String() behavior more consistent and predictable.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions