X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/a7cdd1faaf1de132fa556944bc86831ebdfe8886..50e724b9f45eb25825486e17839e4d2867343caf:/sdk/go/arvados/duration.go diff --git a/sdk/go/arvados/duration.go b/sdk/go/arvados/duration.go index ee482fdf31..9df210ccb0 100644 --- a/sdk/go/arvados/duration.go +++ b/sdk/go/arvados/duration.go @@ -5,6 +5,7 @@ package arvados import ( + "bytes" "encoding/json" "fmt" "strings" @@ -17,12 +18,19 @@ type Duration time.Duration // UnmarshalJSON implements json.Unmarshaler. func (d *Duration) UnmarshalJSON(data []byte) error { + if bytes.Equal(data, []byte(`"0"`)) || bytes.Equal(data, []byte(`0`)) { + // Unitless 0 is not accepted by ParseDuration, but we + // accept it as a reasonable spelling of 0 + // nanoseconds. + *d = 0 + return nil + } if data[0] == '"' { return d.Set(string(data[1 : len(data)-1])) } // Mimic error message returned by ParseDuration for a number // without units. - return fmt.Errorf("missing unit in duration %s", data) + return fmt.Errorf("missing unit in duration %q", data) } // MarshalJSON implements json.Marshaler.