Documentation ¶
Overview ¶
Package duration implements functions to turn durations into a human-readable format.
For consistency reasons, months are always treated as 30 days, and years are always treated as 365 days.
Index ¶
- func Days(d time.Duration) (days int, left time.Duration)
- func Format(d time.Duration) string
- func FormatCustom(d time.Duration, p Parts, join Joiner) string
- func FormatTime(t time.Time) string
- func Hours(d time.Duration) (hours int, left time.Duration)
- func Minutes(d time.Duration) (minutes int, left time.Duration)
- func Months(d time.Duration) (months int, left time.Duration)
- func Years(d time.Duration) (years int, left time.Duration)
- type Joiner
- type Parts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Format ¶
Format returns d as a human-readable string.
If d is <1 month, the formats used are day, hour, minute, and second. If d is <1 year, the formats used are month, day, hour, and minute. In all other cases, the formats used are year, month, day, and hour.
func FormatCustom ¶
FormatCustom is like Format, but allows you to specify your own Parts and Joiner, for localization.
func FormatTime ¶
FormatTime formats t according to format. If t is in the past, returns "<time> ago". If t is in the future, returns "until <time> from now"
Types ¶
type Parts ¶
type Parts struct { Years func(int) string Months func(int) string Days func(int) string Hours func(int) string Minutes func(int) string Seconds func(int) string }
Parts are functions to transform a number into a human-readable string.
func EnglishParts ¶
func EnglishParts() Parts
EnglishParts returns a copy of the default Parts for English.