https://github.com/goschtalt/approx
Package approx adds support for durations of days, weeks and years.
https://github.com/goschtalt/approx
Last synced: 9 months ago
JSON representation
Package approx adds support for durations of days, weeks and years.
- Host: GitHub
- URL: https://github.com/goschtalt/approx
- Owner: goschtalt
- License: bsd-3-clause
- Created: 2023-06-12T23:55:19.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-21T18:48:24.000Z (about 1 year ago)
- Last Synced: 2024-10-22T11:06:22.070Z (about 1 year ago)
- Language: Go
- Size: 129 KB
- Stars: 12
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-go - approx - A Duration extension supporting parsing/printing durations in days, weeks and years. (Date and Time / Search and Analytic Databases)
- awesome-go - approx - A Duration extension supporting parsing/printing durations in days, weeks and years. (Date and Time / Search and Analytic Databases)
- awesome-go-cn - approx
- awesome-go-plus - approx - A Duration extension supporting parsing/printing durations in days, weeks and years.  (Date and Time / Search and Analytic Databases)
- awesome-go - approx - A Duration extension supporting parsing/printing durations in days, weeks and years. (Date and Time / Search and Analytic Databases)
- fucking-awesome-go - approx - A Duration extension supporting parsing/printing durations in days, weeks and years. (Date and Time / Search and Analytic Databases)
- awesome-go-cn - approx
- awesome-go - approx - A Duration extension supporting parsing/printing durations in days, weeks and years. (Date and Time / Search and Analytic Databases)
- awesome-go-with-stars - approx - A Duration extension supporting parsing/printing durations in days, weeks and years. (Date and Time / Search and Analytic Databases)
README
# approx
[](https://github.com/goschtalt/approx/actions/workflows/ci.yml)
[](http://codecov.io/github/goschtalt/approx?branch=main)
[](https://goreportcard.com/report/github.com/goschtalt/approx)
[](https://github.com/goschtalt/approx/releases)
[](https://pkg.go.dev/github.com/goschtalt/approx)
Package approx adds support for durations of days, weeks and years. The code
used is from the go standard library. Only very minor adjustments were made
to enable parsing to support extra units of time.
# Usage
This really simple library allows you to normally use the `time.Duration` object
from the go standard library, but suppliments two functions for handling
approximate time durations.
```golang
package main
import (
"fmt"
"github.com/goschtalt/approx"
)
func main() {
d, err := approx.ParseDuration("1w4d")
if err != nil {
panic(err)
}
fmt.Println(approx.String(d))
fmt.Println(d)
}
```
[Go Playground](https://go.dev/play/p/zX2FeTrC8Qb)