projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
16328: Merge branch 'master' into 16328-keep-proxy-uses-config.yaml-to-find-keepstores
[arvados.git]
/
sdk
/
go
/
arvados
/
duration.go
diff --git
a/sdk/go/arvados/duration.go
b/sdk/go/arvados/duration.go
index 25eed010f26c534ef8e36dfa119065731d1e2ac4..ee482fdf3150f6a2baf126d4d540f2479fe6ba69 100644
(file)
--- a/
sdk/go/arvados/duration.go
+++ b/
sdk/go/arvados/duration.go
@@
-7,6
+7,7
@@
package arvados
import (
"encoding/json"
"fmt"
import (
"encoding/json"
"fmt"
+ "strings"
"time"
)
"time"
)
@@
-19,17
+20,23
@@
func (d *Duration) UnmarshalJSON(data []byte) error {
if data[0] == '"' {
return d.Set(string(data[1 : len(data)-1]))
}
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 %s", data)
}
// MarshalJSON implements json.Marshaler.
}
// MarshalJSON implements json.Marshaler.
-func (d
*
Duration) MarshalJSON() ([]byte, error) {
+func (d Duration) MarshalJSON() ([]byte, error) {
return json.Marshal(d.String())
}
return json.Marshal(d.String())
}
-// String implements fmt.Stringer.
+// String returns a format similar to (time.Duration)String() but with
+// "0m" and "0s" removed: e.g., "1h" instead of "1h0m0s".
func (d Duration) String() string {
func (d Duration) String() string {
- return time.Duration(d).String()
+ s := time.Duration(d).String()
+ s = strings.Replace(s, "m0s", "m", 1)
+ s = strings.Replace(s, "h0m", "h", 1)
+ return s
}
// Duration returns a time.Duration.
}
// Duration returns a time.Duration.