Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duration literals #34267

Closed
mcandre opened this issue Sep 12, 2019 · 5 comments
Closed

Duration literals #34267

mcandre opened this issue Sep 12, 2019 · 5 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@mcandre
Copy link

mcandre commented Sep 12, 2019

Proposal: Duration literals for Go values and associated JSON, YAML representations, in order to reduce the likelihood of mistakes in application configurations.

No more forgetting, wondering about days vs nanoseconds vs seconds vs hours months vs business quarters vs milliseconds. No more gaps and misleading statements in documentation.

No more conversion errors. Just human readable durations, direct to well-defined machine values.

ISO 8601 format for duration literals would be a good place to start.

https://www.digi.com/resources/documentation/digidocs/90001437-13/reference/r_iso_8601_duration_format.htm

@randall77
Copy link
Contributor

randall77 commented Sep 12, 2019

ISO 8601 uses things like "month" and "day" which aren't fixed duration. There's no clear way to translate such a thing into a machine value, e.g. float64 seconds.

@ianlancetaylor
Copy link
Contributor

Can you give an example of how this would be used? I'm not clear on whether you are asking for a change to the language, or a change to an existing standard library package, or a new standard library package.

See also https://golang.org/pkg/time/#ParseDuration.

@ianlancetaylor
Copy link
Contributor

And, of course, the Go standard library already has type time.Duration and you can already write code like

const shortMonth = 30 * 24 * time.Hour
const longMonth = 31 * 24 * time.Hour
const februaryStandard = 28 * 24 * time.Hour
const februaryLeap = 29 * 24 * time.Hour

@bcmills
Copy link
Contributor

bcmills commented Sep 13, 2019

No more conversion errors.

See also #20757.

@mvdan mvdan added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Sep 13, 2019
@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Oct 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

6 participants