-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
35 lines (28 loc) · 986 Bytes
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package haproxytime_test
import (
"fmt"
"os"
"github.com/frobware/haproxytime"
)
// ExampleParseDuration gets copied to the documentation.
func ExampleParseDuration() {
if duration, err := haproxytime.ParseDuration("1h", haproxytime.Millisecond, haproxytime.ParseModeSingleUnit, haproxytime.NoRangeChecking); err != nil {
fmt.Fprintln(os.Stderr, err)
} else {
fmt.Printf("%vms\n", duration.Milliseconds())
}
if duration, err := haproxytime.ParseDuration("24d20h31m23s647ms", haproxytime.Millisecond, haproxytime.ParseModeMultiUnit, haproxytime.NoRangeChecking); err != nil {
fmt.Fprintln(os.Stderr, err)
} else {
fmt.Printf("%vms\n", duration.Milliseconds())
}
if duration, err := haproxytime.ParseDuration("500", haproxytime.Millisecond, haproxytime.ParseModeMultiUnit, haproxytime.NoRangeChecking); err != nil {
fmt.Fprintln(os.Stderr, err)
} else {
fmt.Printf("%vms\n", duration.Milliseconds())
}
// Output:
// 3600000ms
// 2147483647ms
// 500ms
}