-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed as duplicate of#32313
Description
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.
-
Parsing: A new function to parse the ISO 8601 duration string.
func ParseISO8601Duration(s string) (time.Duration, error)
-
Formatting: A new method on
time.Durationto return an ISO 8601 string.func (d time.Duration) ISO8601String() string
Benefits
- Standard Compliance: Aligns the
timepackage 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.