Merge branch 'master' into 15106-trgm-text-search
[arvados.git] / sdk / go / arvados / duration.go
index d3e11c7a5e673aebe84cbb98a807fa0ef1806b64..2696fdb051146ca34bd311e7e29e1092b0a3723e 100644 (file)
@@ -7,6 +7,7 @@ package arvados
 import (
        "encoding/json"
        "fmt"
+       "strings"
        "time"
 )
 
@@ -27,9 +28,13 @@ func (d Duration) MarshalJSON() ([]byte, error) {
        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 {
-       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.