https://github.com/ctrlaltdev/justamin
Golang Humanized Duration
https://github.com/ctrlaltdev/justamin
Last synced: 3 months ago
JSON representation
Golang Humanized Duration
- Host: GitHub
- URL: https://github.com/ctrlaltdev/justamin
- Owner: ctrlaltdev
- License: mpl-2.0
- Created: 2021-07-19T01:30:45.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-07-19T19:29:50.000Z (over 4 years ago)
- Last Synced: 2025-04-09T01:31:16.871Z (9 months ago)
- Language: Go
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Duration for Humans
Provided a time.Duration or a time.Time, will return a human representation of the duration.
## Installation
```sh
go get -u github.com/ctrlaltdev/justamin
```
## How To Use
Humanize a time.Duration:
```go
package main
import (
"github.com/ctrlaltdev/justamin"
)
func main() {
// ...
d := time.Duration(49 * 3600 * 1000000000)
humanized := justamin.Humanize(d)
// will return "in 2 days"
// ...
}
```
Humanize a time.Time (will humanize relatively to time.Now()):
```go
package main
import (
"github.com/ctrlaltdev/justamin"
)
func main() {
// ...
t := time.Now().Add(-time.Duration(3600 * 1000000000))
humanized := justamin.Duration(t)
// will return "an hour ago"
// ...
}
```