projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
21204: Merge branch '21204-stable-log-sort' from arvados-workbench2.git
[arvados.git]
/
sdk
/
go
/
arvados
/
duration.go
diff --git
a/sdk/go/arvados/duration.go
b/sdk/go/arvados/duration.go
index ee482fdf3150f6a2baf126d4d540f2479fe6ba69..9df210ccb016ef85327b9eaf09ca3aacec0ae9f2 100644
(file)
--- a/
sdk/go/arvados/duration.go
+++ b/
sdk/go/arvados/duration.go
@@
-5,6
+5,7
@@
package arvados
import (
package arvados
import (
+ "bytes"
"encoding/json"
"fmt"
"strings"
"encoding/json"
"fmt"
"strings"
@@
-17,12
+18,19
@@
type Duration time.Duration
// UnmarshalJSON implements json.Unmarshaler.
func (d *Duration) UnmarshalJSON(data []byte) error {
// 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.
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.
}
// MarshalJSON implements json.Marshaler.