Skip to content

denwwer/go-hd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hd

Coverage Go Report Card Go Reference

Humanize Duration (hd) – Go package that works like Duration.String() but returns a calendar-accurate difference (years, months, days, hours, minutes, seconds) for human-friendly output.

go get github.com/denwwer/go-hd

Usage Example

Since

Like time.Since, with nil location defaults to UTC.

date := time.Date(2024, 3, 14, 10, 30, 0, 0, time.UTC) 

d := hd.Since(date, nil)
d.Years // => 1
d.Months // => 6
d.Days // => 8
d.String() // => 1y 6m 8d 5h 8m 17s

Between

Between two specific times with nil location.

start := time.Date(2022, 3, 14, 10, 0, 0, 0, time.UTC)
end := time.Date(2023, 3, 14, 12, 0, 0, 0, time.UTC)

d := Between(start, end, nil)
d.String() // => 1y 2h

With location.

loc, _ := time.LoadLocation("America/New_York")
start := time.Date(2025, 9, 22, 0, 0, 0, 0, time.UTC)
end := time.Date(2025, 9, 23, 12, 30, 15, 0, time.UTC)

d := Between(start, end, loc)
d.String() // => 1d 12h 30m 15s

About

Package hd (Humanize Duration) is like Duration.String(), but more human-friendly

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages