support combo new and old
parent
d5ec073f75
commit
9301ddd467
|
|
@ -83,6 +83,7 @@ func ToDuration(s string) time.Duration {
|
||||||
for len(substr) > 0 && (substr[len(substr)-1] >= '0' && substr[len(substr)-1] <= '9') {
|
for len(substr) > 0 && (substr[len(substr)-1] >= '0' && substr[len(substr)-1] <= '9') {
|
||||||
substr = substr[:len(substr)-1]
|
substr = substr[:len(substr)-1]
|
||||||
}
|
}
|
||||||
|
s = strings.ReplaceAll(s, substr, "")
|
||||||
substr = strings.TrimSuffix(substr, c.key)
|
substr = strings.TrimSuffix(substr, c.key)
|
||||||
n, _ := strconv.Atoi(substr)
|
n, _ := strconv.Atoi(substr)
|
||||||
d += c.d * time.Duration(n)
|
d += c.d * time.Duration(n)
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,7 @@ func TestToDuration(t *testing.T) {
|
||||||
"simple": {input: "1s", want: time.Second},
|
"simple": {input: "1s", want: time.Second},
|
||||||
"compound": {input: "1m1s", want: time.Minute + time.Second},
|
"compound": {input: "1m1s", want: time.Minute + time.Second},
|
||||||
"compound:unsorted": {input: "1s1m", want: time.Minute + time.Second},
|
"compound:unsorted": {input: "1s1m", want: time.Minute + time.Second},
|
||||||
|
"compound:extension": {input: "1d1m", want: time.Minute + time.Hour*24},
|
||||||
"extension:day": {input: "1d", want: 24 * time.Hour},
|
"extension:day": {input: "1d", want: 24 * time.Hour},
|
||||||
"extension:week": {input: "1w", want: 24 * 7 * time.Hour},
|
"extension:week": {input: "1w", want: 24 * 7 * time.Hour},
|
||||||
"extension:week,day": {input: "1w1d", want: 24 * 8 * time.Hour},
|
"extension:week,day": {input: "1w1d", want: 24 * 8 * time.Hour},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue