-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_offset_time_test.go
61 lines (45 loc) · 1.2 KB
/
example_offset_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 ExampleOffsetTimeOf() {
t := chrono.OffsetTimeOf(12, 30, 15, 0, 2, 0)
fmt.Println(t)
// Output: 12:30:15+02:00
}
func ExampleOffsetTime_BusinessHour() {
t := chrono.OffsetTimeOf(24, 15, 0, 0, 2, 0)
fmt.Println(t.BusinessHour())
// Output: 24
}
func ExampleOffsetTime_Sub() {
t1 := chrono.OffsetTimeOf(12, 30, 0, 0, 1, 0)
t2 := chrono.OffsetTimeOf(12, 15, 0, 0, 2, 0)
fmt.Println(t1.Sub(t2))
// Output: PT1H15M
}
func ExampleOffsetTime_Add() {
t := chrono.OffsetTimeOf(12, 30, 0, 0, 2, 0)
fmt.Println(t.Add(4 * chrono.Hour))
// Output: 16:30:00+02:00
}
func ExampleOffsetTime_Compare() {
t1 := chrono.OffsetTimeOf(12, 30, 0, 0, 1, 0)
t2 := chrono.OffsetTimeOf(12, 30, 0, 0, 2, 0)
if t2.Compare(t1) == -1 {
fmt.Println(t2, "is before", t1)
}
// Output: 12:30:00+02:00 is before 12:30:00+01:00
}
func ExampleOffsetTime_Format() {
t := chrono.OffsetTimeOf(12, 30, 15, 0, 2, 30)
fmt.Println(t.Format(chrono.ISO8601TimeExtended))
// Output: T12:30:15+02:30
}
func ExampleOffsetTime_Parse() {
var t chrono.OffsetTime
t.Parse(chrono.ISO8601TimeExtended, "T12:30:15+02:30")
fmt.Println(t)
// Output: 12:30:15+02:30
}