8784: Fix test for latest firefox.
[arvados.git] / sdk / go / stats / duration.go
1 package stats
2
3 import (
4         "fmt"
5         "strconv"
6         "time"
7 )
8
9 // Duration is a duration that is displayed as a number of seconds in
10 // fixed-point notation.
11 type Duration time.Duration
12
13 // MarshalJSON implements json.Marshaler.
14 func (d Duration) MarshalJSON() ([]byte, error) {
15         return []byte(d.String()), nil
16 }
17
18 // String implements fmt.Stringer.
19 func (d Duration) String() string {
20         return fmt.Sprintf("%.6f", time.Duration(d).Seconds())
21 }
22
23 // UnmarshalJSON implements json.Unmarshaler
24 func (d *Duration) UnmarshalJSON(data []byte) error {
25         return d.Set(string(data))
26 }
27
28 // Value implements flag.Value
29 func (d *Duration) Set(s string) error {
30         sec, err := strconv.ParseFloat(s, 64)
31         if err == nil {
32                 *d = Duration(sec * float64(time.Second))
33         }
34         return err
35 }