Skip to content

Unexpected results from the duration format #523

@cbandy

Description

@cbandy

The OpenAPI definition of the duration format follows RFC 3339. The Kubernetes definition is more relaxed, which is nice, but IsDuration allows text that produces unexpected values from ParseDuration and unmarshaling.

https://go.dev/play/p/kZhy7fepBAM

I expected 1.5 hours to be 90 minutes, but this valid text is interpreted as 5 hours:

fmt.Println(time.ParseDuration("1.5h"))        // 1h30m0s <nil>
fmt.Println(strfmt.ParseDuration("1.5 hours")) // 5h0m0s <nil>

I expected 1.5 days to be 36 hours, but this valid text is interpreted as 120 hours:

fmt.Println(strfmt.ParseDuration("1.5 days")) // 120h0m0s <nil>
fmt.Println(1.5 * 24 * time.Hour)             // 36h0m0s

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions