1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
13 // Duration is a duration that is displayed as a number of seconds in
14 // fixed-point notation.
15 type Duration time.Duration
17 // MarshalJSON implements json.Marshaler.
18 func (d Duration) MarshalJSON() ([]byte, error) {
19 return []byte(d.String()), nil
22 // String implements fmt.Stringer.
23 func (d Duration) String() string {
24 return fmt.Sprintf("%.6f", time.Duration(d).Seconds())
27 // UnmarshalJSON implements json.Unmarshaler
28 func (d *Duration) UnmarshalJSON(data []byte) error {
29 return d.Set(string(data))
32 // Set implements flag.Value
33 func (d *Duration) Set(s string) error {
34 sec, err := strconv.ParseFloat(s, 64)
36 *d = Duration(sec * float64(time.Second))