Skip to content

proposal: time: add support for ISO 8601 duration format #75938

@EricGusmao

Description

@EricGusmao

Proposal Details

This proposal suggests adding two new functions to the time package: one to parse the standard ISO 8601 duration format and another to format a time.Duration into an ISO 8601 string.

Problem

The standard library's time.ParseDuration function only supports a simple format (e.g., 1h30m) and cannot handle the widely-used ISO 8601 duration standard. This format is common in APIs, database systems, and configuration files.

Proposed Solution

This proposal suggests adding a parsing function and a formatting method. The names used here are illustrative and would be subject to discussion during the review process.

  1. Parsing: A new function to parse the ISO 8601 duration string.

    func ParseISO8601Duration(s string) (time.Duration, error)
  2. Formatting: A new method on time.Duration to return an ISO 8601 string.

    func (d time.Duration) ISO8601String() string

Benefits

  • Standard Compliance: Aligns the time package with a major international standard used across the industry.
  • Improved Interoperability: Simplifies working with other systems and services that produce or consume ISO 8601 durations.
  • Enhanced Developer Experience: Provides a robust, built-in solution for a common task, removing the need for external dependencies or boilerplate code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions