Skip to content

Xiol/human_duration

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Human Duration Build Status GoDoc

A little Go util to print duration strings in a human-friendly format

Docs

The String function takes a Duration and the precision that's important to the user.

The allowed precisions are year, day, hour, minute and second

Usage

import "github.com/davidbanham/human_duration"

example := time.Hour * 25 + time.Minute * 4 + time.Second * 8

fmt.Println(human_duration.String(example, "second") // 1 day 4 minutes 8 seconds
fmt.Println(human_duration.String(example, "minute") // 1 day 4 minutes
fmt.Println(human_duration.String(example, "day") // 1 day

day := time.Hour * 24
year := day * 365

longExample := year * 4 + day * 2

fmt.Println(human_duration.String(longExample, "second") // 4 years 2 days

There are more examples in the tests.

Credit

Adapted and extended from (this gist)[https://gist.github.com/harshavardhana/327e0577c4fed9211f65]

About

A little Go util to print duration strings in a human-friendly format

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%