Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Go
  3. go-str2duration

go-str2duration

BSD-3-ClauseGov2.1.0

A Go package that converts strings to time.Duration with support for weeks and days.

GitHubGitHub
118 stars11 forks0 contributors

What is go-str2duration?

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.

Target Audience

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.

Value Proposition

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.

Overview

Convert string to duration in golang

Use Cases

Best For

  • Parsing configuration files with human-readable duration strings like '2w3d'
  • CLI tools that accept duration arguments with weeks and days
  • Applications needing to calculate or display long-term intervals
  • Scheduling systems that operate on weekly or daily cycles
  • Converting between readable duration formats and Go's time.Duration
  • Enhancing time parsing in Go projects without breaking existing functionality

Not Ideal For

  • Applications that only parse standard Go duration strings without weeks or days
  • Projects requiring localization or cultural-specific time unit formats
  • Systems needing to handle variable-length days (e.g., business days) or calendar months
  • High-performance code where minimizing external dependencies is critical

Pros & Cons

Pros

Extended Unit Support

Adds week ('w') and day ('d') parsing beyond Go's standard library, as shown in examples like '1w2d6h3ns', making it suitable for longer intervals.

Backward Compatibility

Fully supports all strings from Go's native time.Duration.String(), ensuring seamless integration with existing code that uses standard duration formats.

Clean String Conversion

Converts durations back to strings without unnecessary decimals and omits zero-value units, improving readability compared to the standard library's output.

Microsecond Flexibility

Accepts both 'µs' and 'us' as microsecond units, providing aliases for better compatibility with different input sources.

Cons

Fixed Time Assumptions

Assumes a day is always 24 hours, ignoring complexities like daylight saving time or business days, which limits use in calendar-aware applications.

No Larger Units

Lacks support for months or years, restricting its usefulness for parsing durations that involve variable-length calendar periods.

External Dependency Overhead

Introduces a third-party package for functionality that could be implemented with custom code if only basic extensions are needed, adding maintenance burden.

Frequently Asked Questions

Quick Stats

Stars118
Forks11
Contributors0
Open Issues1
Last commit2 years ago
CreatedSince 2020

Tags

#string-conversion#time-parsing#convert#golang-library#string#golang#duration#go#parser#utilities#time-duration

Built With

G
Go

Included in

Go169.1k
Auto-fetched 18 hours ago

Related Projects

carboncarbon

A simple, semantic and developer-friendly time package for golang

Stars5,225
Forks266
Last commit4 days ago
nownow

Now is a time toolkit for golang

Stars4,699
Forks240
Last commit5 months ago
dateparsedateparse

GoLang Parse many date strings without knowing format in advance.

Stars2,145
Forks174
Last commit2 years ago
carboncarbon

Carbon for Golang, an extension for Time

Stars781
Forks55
Last commit2 years ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub