https://github.com/k1low/duration
duration.Parse() parses a formatted string and returns the time.Duration value it represents.
https://github.com/k1low/duration
duration parser time
Last synced: 10 months ago
JSON representation
duration.Parse() parses a formatted string and returns the time.Duration value it represents.
- Host: GitHub
- URL: https://github.com/k1low/duration
- Owner: k1LoW
- License: mit
- Created: 2019-09-14T03:03:35.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2022-09-23T07:20:16.000Z (over 3 years ago)
- Last Synced: 2025-03-29T05:41:40.758Z (10 months ago)
- Topics: duration, parser, time
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 10
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# duration [](https://github.com/k1LoW/duration/actions/workflows/ci.yml) [](https://godoc.org/github.com/k1LoW/duration)
`duration.Parse()` parses a formatted string and returns the time.Duration value it represents.
## Usage
``` go
package duration_test
import (
"fmt"
"github.com/k1LoW/duration"
)
func ExampleParse() {
d, _ := duration.Parse("3 days 4 hours")
fmt.Printf("%s", d)
// Output: 76h0m0s
}
```
## Supported unit of time
| Unit of time | value |
| --- | --- |
| ns | time.Nanosecond |
| nsec | time.Nanosecond |
| nanosecond | time.Nanosecond |
| nanoseconds | time.Nanosecond |
| us | time.Microsecond |
| usec | time.Microsecond |
| microsecond | time.Microsecond |
| microseconds | time.Microsecond |
| ms | time.Millisecond |
| msec | time.Millisecond |
| millisecond | time.Millisecond |
| milliseconds | time.Millisecond |
| s | time.Second |
| sec | time.Second |
| second | time.Second |
| seconds | time.Second |
| m | time.Minute |
| min | time.Minute |
| minute | time.Minute |
| minutes | time.Minute |
| h | time.Hour |
| hour | time.Hour |
| hours | time.Hour |
| d | time.Hour * 24 |
| day | time.Hour * 24 |
| days | time.Hour * 24 |
| w | time.Hour * 24 * 7 |
| week | time.Hour * 24 * 7 |
| weeks | time.Hour * 24 * 7 |