X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/6c78b28f9f54664babc57a4b4372c502065ed5d1..50e724b9f45eb25825486e17839e4d2867343caf:/sdk/go/arvados/duration.go diff --git a/sdk/go/arvados/duration.go b/sdk/go/arvados/duration.go index 2696fdb051..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,10 +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])) } - return fmt.Errorf("duration must be given as a string like \"600s\" or \"1h30m\"") + // Mimic error message returned by ParseDuration for a number + // without units. + return fmt.Errorf("missing unit in duration %q", data) } // MarshalJSON implements json.Marshaler.