X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/927524f1be454de021180b74999d682780b8cb6b..eccb6ba135ebe1bc73bdeeed89150d3c4ee26126:/sdk/go/arvados/duration.go diff --git a/sdk/go/arvados/duration.go b/sdk/go/arvados/duration.go index c922f0a30d..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,6 +18,13 @@ 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])) }