diff --git a/db.go b/db.go index f407a39..16a34d6 100644 --- a/db.go +++ b/db.go @@ -3,7 +3,6 @@ package main import ( "errors" "fmt" - "log" "strconv" "time" @@ -91,8 +90,20 @@ func (db db) lastTS(user, q string) time.Time { } func (d duration) MarshalYAML() (interface{}, error) { - log.Println("marshalling duration", time.Duration(d)) - return time.Duration(d).String(), nil + return d.String(), nil +} + +func (d duration) String() string { + result := "" + if weeks := time.Duration(d) / (time.Hour * 24 * 7); weeks > 0 { + result += fmt.Sprintf("%dw", weeks) + d -= duration(weeks * time.Hour * 24 * 7) + } + if days := time.Duration(d) / (time.Hour * 24); days > 0 { + result += fmt.Sprintf("%dd", days) + d -= duration(days * time.Hour * 24) + } + return result + time.Duration(d).String() } func (d *duration) UnmarshalYAML(unmarshal func(interface{}) error) error {