statping/utils/time.go

25 lines
442 B
Go
Raw Normal View History

2018-10-05 04:28:38 +00:00
package utils
import (
"github.com/hako/durafmt"
2018-10-05 04:28:38 +00:00
"time"
)
// Now returns the UTC timestamp
func Now() time.Time {
return time.Now().UTC()
}
type Duration struct {
time.Duration
}
func (d Duration) Human() string {
return durafmt.Parse(d.Duration).LimitFirstN(2).String()
}
2018-10-07 04:48:33 +00:00
// FormatDuration converts a time.Duration into a string
2018-10-05 04:28:38 +00:00
func FormatDuration(d time.Duration) string {
return durafmt.ParseShort(d).LimitFirstN(3).String()
2018-10-05 04:28:38 +00:00
}