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

Change formatting/marshaling of time.Duration #3486

Open
aurelius-adrian opened this issue Jan 15, 2025 · 0 comments
Open

Change formatting/marshaling of time.Duration #3486

aurelius-adrian opened this issue Jan 15, 2025 · 0 comments

Comments

@aurelius-adrian
Copy link

Proposal:

Seeing that the duration of a month varies greatly depending on which month in which year, marshaling time.Duration into ISO8601 with a month component would be ambiguous. As far as I know there is no context contained within the time.Duration type, as it is saved as a duration in nano seconds (int64). Therefore time.Duration should be marshaled into ISO8601 without year and month components.

According to ISO8601 3.1.1.8
"...The exact duration of a time scale unit (3.1.1.7) depends on the time scale (3.1.1.5) used. For example, the durations of a year, month, week, day, hour or minute, may depend on when they occur [in a Gregorian calendar (3.1.1.19), a calendar month (3.1.2.19) can have a duration of 28, 29, 30, or 31 days; in a 24-hour clock (3.1.1.10), a clock minute (3.1.2.4) can have a duration of 59, 60, or 61 seconds, etc.]. Therefore, the exact duration can only be evaluated if the exact duration of each is known.
Note 4 to entry: This definition is closely related to NOTE 1 of the terminological entry “ duration ” in IEC 60050-113:2011, 113-01-13."

I understand that the ISO definition states that even the number of minutes within a hour can vary, I believe in practice most parsers assume a 60min hour, however parsers, at least those I require, do not assume a fixed duration in ns for the Month component - resulting in errors when unmarshaling time.Duration.

The imported library:

dur "github.com/sosodev/duration"

which is used here:

return MarshalString(dur.Format(d))

sets a fixed month component duration here:
https://github.com/sosodev/duration/blob/b7258bf670d35309ff417d0ab25fc77f9d338cfa/duration.go#L40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant