yaml marshal fat durations
parent
5b2d89a73a
commit
ca09d6f966
17
db.go
17
db.go
|
|
@ -3,7 +3,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -91,8 +90,20 @@ func (db db) lastTS(user, q string) time.Time {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d duration) MarshalYAML() (interface{}, error) {
|
func (d duration) MarshalYAML() (interface{}, error) {
|
||||||
log.Println("marshalling duration", time.Duration(d))
|
return d.String(), nil
|
||||||
return time.Duration(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 {
|
func (d *duration) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue