Handrolling ISO8601 Duration Support for Go
9 months ago
- #ISO8601
- #Go
- #Parsing
- Author created a custom ISO8601 duration parsing library in Go due to lack of suitable existing libraries.
- ISO8601 duration format is complex, starting with 'P' and including designators for years (Y), months (M), days (D), hours (H), minutes (M), and seconds (S).
- Existing Go libraries either lacked ISO8601 duration support or were non-compliant with the specification.
- The author's library, go-iso8601-duration, implements a finite state machine (FSM) to parse ISO8601 durations accurately.
- The FSM handles various states and transitions to ensure correct parsing, including error handling for invalid inputs.
- The library provides methods to convert ISO8601 durations to Go's time.Duration and apply them to time.Time instances.
- Extensive testing was conducted to ensure compliance with the ISO8601 specification and handle edge cases.
- The author criticizes ISO for not making standards freely accessible, despite taxpayer funding.