A Go package that converts strings to time.Duration with support for weeks and days.
go-str2duration is a Go library that converts human-readable duration strings into Go's native `time.Duration` type. It solves the limitation of Go's standard `time.ParseDuration` by adding support for weeks and days, allowing developers to parse longer time intervals easily. The library maintains full compatibility with standard duration strings while providing a cleaner, more readable format for output.
Go developers who need to parse or represent durations longer than hours, such as in configuration files, CLI tools, or applications dealing with scheduling, timeouts, or interval calculations.
Developers choose go-str2duration because it seamlessly extends Go's built-in time parsing with week and day support, offers a cleaner string representation than the standard library, and maintains full backward compatibility with existing `time.Duration` strings.
Convert string to duration in golang
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Adds week ('w') and day ('d') parsing beyond Go's standard library, as shown in examples like '1w2d6h3ns', making it suitable for longer intervals.
Fully supports all strings from Go's native time.Duration.String(), ensuring seamless integration with existing code that uses standard duration formats.
Converts durations back to strings without unnecessary decimals and omits zero-value units, improving readability compared to the standard library's output.
Accepts both 'µs' and 'us' as microsecond units, providing aliases for better compatibility with different input sources.
Assumes a day is always 24 hours, ignoring complexities like daylight saving time or business days, which limits use in calendar-aware applications.
Lacks support for months or years, restricting its usefulness for parsing durations that involve variable-length calendar periods.
Introduces a third-party package for functionality that could be implemented with custom code if only basic extensions are needed, adding maintenance burden.