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

proposal: add MarshalText/UnmarshalText to time.Duration #16039

Closed
bystones opened this issue Jun 11, 2016 · 3 comments
Closed

proposal: add MarshalText/UnmarshalText to time.Duration #16039

bystones opened this issue Jun 11, 2016 · 3 comments

Comments

@bystones
Copy link

bystones commented Jun 11, 2016

Adding these methods to time.Duration would make it easier to write and read JSON data containing time.Duration objects. In Go 1.7 it will be possible to use maps in which the keys implement the two methods for marshalling and unmarshalling JSON.

Like time.Time the amount of code added should be minimal, as time.ParseDuration and time.Duration.String are already in place.

Some projects already wrap the time.Duration type to get this behavior:

@bystones bystones changed the title proposal: add MarshalJSON/UnmarshalJSON and MarshalText/UnmarshalText to time.Duration proposal: add MarshalText/UnmarshalText to time.Duration Jun 11, 2016
@ianlancetaylor ianlancetaylor added this to the Proposal milestone Jun 12, 2016
Shelnutt2 added a commit to Shelnutt2/go that referenced this issue Jun 25, 2016
This add support for MarshalJSON, MarshalText and MarshalBinary
to the time.Duration type.
@Shelnutt2
Copy link

I've implemented the marshal/unmarshal support via https://golang.org/cl/24473.

@gopherbot
Copy link

CL https://golang.org/cl/24473 mentions this issue.

@bradfitz
Copy link
Contributor

Sorry, I think we're going to reject this on the grounds that the JSON spec does not define a way to stringify time durations. It also adds too much complexity and awareness of JSON to the low-level time package.

@golang golang locked and limited conversation to collaborators Aug 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants