Change formatting/marshaling of time.Duration
- Lingua principale
- Go
- Stelle
- 10.8k
- Fork
- 1.3k
- Merge medio
- 2g 36m
- PR unite (30g)
- 26
Descrizione
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 ](https://www.iso.org/obp/ui/en/#iso:std:iso:8601:-1:ed-1:v1:en:term:3.1.1.8)
"...The exact duration of a [time scale unit (3.1.1.7)](https://www.iso.org/obp/ui/en/#iso:std:iso:8601:-1:ed-1:v1:en:term:3.1.1.7) depends on the [time scale (3.1.1.5)](https://www.iso.org/obp/ui/en/#iso:std:iso:8601:-1:ed-1:v1:en:term: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)](https://www.iso.org/obp/ui/en/#iso:std:iso:8601:-1:ed-1:v1:en:term:3.1.1.19), a [calendar month (3.1.2.19)](https://www.iso.org/obp/ui/en/#iso:std:iso:8601:-1:ed-1:v1:en:term:3.1.2.19) can have a duration of 28, 29, 30, or 31 days; in a [24-hour clock (3.1.1.10)](https://www.iso.org/obp/ui/en/#iso:std:iso:8601:-1:ed-1:v1:en:term:3.1.1.10), a [clock minute (3.1.2.4)](https://www.iso.org/obp/ui/en/#iso:std:iso:8601:-1:ed-1:v1:en:term: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:
https://github.com/99designs/gqlgen/blob/7b1908e955f5f7e2fa5701114f8b865074b436cc/graphql/duration.go#L7
which is used here:
https://github.com/99designs/gqlgen/blob/7b1908e955f5f7e2fa5701114f8b865074b436cc/graphql/duration.go#L26
sets a fixed month component duration here:
https://github.com/sosodev/duration/blob/b7258bf670d35309ff417d0ab25fc77f9d338cfa/duration.go#L40
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.