9 // Duration is a duration that is displayed as a number of seconds in
10 // fixed-point notation.
11 type Duration time.Duration
13 // MarshalJSON implements json.Marshaler.
14 func (d Duration) MarshalJSON() ([]byte, error) {
15 return []byte(d.String()), nil
18 // String implements fmt.Stringer.
19 func (d Duration) String() string {
20 return fmt.Sprintf("%.6f", time.Duration(d).Seconds())
23 // UnmarshalJSON implements json.Unmarshaler
24 func (d *Duration) UnmarshalJSON(data []byte) error {
25 return d.Set(string(data))
28 // Value implements flag.Value
29 func (d *Duration) Set(s string) error {
30 sec, err := strconv.ParseFloat(s, 64)
32 *d = Duration(sec * float64(time.Second))