https://github.com/mashiike/longduration
Package for go's time.Duration extension
https://github.com/mashiike/longduration
Last synced: 3 months ago
JSON representation
Package for go's time.Duration extension
- Host: GitHub
- URL: https://github.com/mashiike/longduration
- Owner: mashiike
- License: mit
- Created: 2022-11-22T08:12:05.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-05-22T21:01:01.000Z (about 2 years ago)
- Last Synced: 2024-06-20T16:49:22.519Z (12 months ago)
- Language: Go
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# longduration
[](https://godoc.org/github.com/mashiike/longduration)


[](https://goreportcard.com/report/mashiike/longduration)
[](https://github.com/mashiike/longduration/blob/master/LICENSE)go utility package for long duration
-----
The standard go package does not have a duration expression beyond hour due to concerns about daylight saving time, leap seconds, etc.
However, in actual use, I would like to see notations such as `1d`, `3d`, `23d` etc.... Therefore, we have decided to use the following expression, which does not take into account daylight saving time, leap seconds, etc.
1d = 24hour, which does not take into account daylight saving time, leap seconds, and so on.**Note: Do not use this package if you are affected by daylight saving time zones!**
## Requirements
* Go 1.16 or higher. support the 3 latest versions of Go.See [godoc.org/github.com/mashiike/longduration](https://godoc.org/github.com/mashiike/longduration).
-----
## Installation
```shell
$ go get -u github.com/mashiike/longduration
```## Usage
```go
package mainimport (
"fmt""github.com/mashiike/longduration"
)func main() {
years, _ := longduration.ParseDuration("1y")
weeks, _ := longduration.ParseDuration("4w")
days, _ := longduration.ParseDuration("3d")
hours, _ := longduration.ParseDuration("25h")
complex, _ := longduration.ParseDuration("1d2h34m10s")
fmt.Println(longduration.DurationString(years))
fmt.Println(longduration.DurationString(weeks, longduration.WithWeek()))
fmt.Println(longduration.DurationString(days))
fmt.Println(longduration.DurationString(hours))
fmt.Println(longduration.DurationString(complex))
fmt.Printf("There are %.4f weeks in %s.\n", longduration.Weeks(years), longduration.DurationString(years, longduration.WithYear()))
fmt.Printf("There are %.0f days in %s.\n", longduration.Days(weeks), longduration.DurationString(weeks, longduration.WithWeek()))
fmt.Printf("There are %.0f hours in %s.\n", days.Hours(), longduration.DurationString(days))
fmt.Printf("There are %.0f hours in %s.\n", hours.Hours(), longduration.DurationString(hours))
fmt.Printf("There are %.0f seconds in %s.\n", complex.Seconds(), longduration.DurationString(complex))
// Output:
// 365d
// 4w
// 3d
// 1d1h
// 1d2h34m10s
// There are 52.1429 weeks in 1y.
// There are 28 days in 4w.
// There are 72 hours in 3d.
// There are 25 hours in 1d1h.
// There are 95650 seconds in 1d2h34m10s.
}
```## LICENSE
MIT