-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_local_time_test.go
61 lines (45 loc) · 1.09 KB
/
example_local_time_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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package chrono_test
import (
"fmt"
"github.com/go-chrono/chrono"
)
func ExampleLocalTimeOf() {
t := chrono.LocalTimeOf(12, 30, 15, 0)
fmt.Println(t)
// Output: 12:30:15
}
func ExampleLocalTime_BusinessHour() {
t := chrono.LocalTimeOf(24, 15, 0, 0)
fmt.Println(t.BusinessHour())
// Output: 24
}
func ExampleLocalTime_Sub() {
t1 := chrono.LocalTimeOf(12, 30, 0, 0)
t2 := chrono.LocalTimeOf(12, 15, 0, 0)
fmt.Println(t1.Sub(t2))
// Output: PT15M
}
func ExampleLocalTime_Add() {
t := chrono.LocalTimeOf(12, 30, 0, 0)
fmt.Println(t.Add(4 * chrono.Hour))
// Output: 16:30:00
}
func ExampleLocalTime_Compare() {
t1 := chrono.LocalTimeOf(12, 30, 0, 0)
t2 := chrono.LocalTimeOf(12, 15, 0, 0)
if t2.Compare(t1) == -1 {
fmt.Println(t2, "is before", t1)
}
// Output: 12:15:00 is before 12:30:00
}
func ExampleLocalTime_Format() {
t := chrono.LocalTimeOf(12, 30, 15, 0)
fmt.Println(t.Format(chrono.ISO8601TimeExtended))
// Output: T12:30:15
}
func ExampleLocalTime_Parse() {
var t chrono.LocalTime
t.Parse(chrono.ISO8601TimeExtended, "T12:30:15")
fmt.Println(t)
// Output: 12:30:15
}