Skip to content

encoding/json: custom format for time.Duration #4712

@wcn3

Description

@wcn3
Feature request:

JSON struct tags could be enhanced to provide the notion of time units since the parser
currently assumes everything is ns, causing workarounds of the type that may need to get
fixed, as in https://golang.org/cl/7086059

Sample code: http://play.golang.org/p/CZH9ThvhxK

What is the expected output?
&{Access:12345 Refresh:23456 ExpiresIn:1h0m0s ValidIn:1.234us}
2013-01-21 22:37:40.646947673 -0800 PST
2013-01-21 23:37:40.647083585 -0800 PST

What do you see instead?
&{Access:12345 Refresh:23456 ExpiresIn:3.6us ValidIn:1.234us}
2009-11-10 23:00:00 +0000 UTC
2009-11-10 23:00:00.0000036 +0000 UTC

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions