-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvtime_test.go
111 lines (106 loc) · 2.46 KB
/
vtime_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package vtime
import (
"testing"
"time"
_ "time/tzdata"
)
func TestUnix(t *testing.T) {
v := Unix(1668174735).UTC() // Fri Nov 11 2022 13:52:15 GMT+0000
if v.Year() != 2022 {
t.Errorf("Expected 2022, got %d", v.Year())
}
if v.Month() != time.November {
t.Errorf("Expected November, got %s", v.Month())
}
if v.Day() != 11 {
t.Errorf("Expected 11, got %d", v.Day())
}
if v.Hour() != 13 {
t.Errorf("Expected 13, got %d", v.Hour())
}
if v.Minute() != 52 {
t.Errorf("Expected 52, got %d", v.Minute())
}
if v.Second() != 15 {
t.Errorf("Expected 15, got %d", v.Second())
}
Seoul, err := time.LoadLocation("Asia/Seoul") // "time/tzdata" is required
if err != nil {
t.Error(err)
}
v = v.In(Seoul) // Fri Nov 11 2022 22:52:15 GMT+0900 (한국 표준시)
if v.Hour() != 22 {
t.Error("Expected 22, got", v.Hour())
}
if v.Minute() != 52 {
t.Error("Expected 52, got", v.Minute())
}
if v.Second() != 15 {
t.Error("Expected 15, got", v.Second())
}
if v.Nanosecond() != 0 {
t.Error("Expected 0, got", v.Nanosecond())
}
d := v.Date() // 2022-11-11
if d.Year != 2022 {
t.Error("Expected 2022, got", d.Year)
}
if d.Month != time.November {
t.Error("Expected 11, got", d.Month)
}
if d.Day != 11 {
t.Error("Expected 11, got", d.Day)
}
}
func TestSet(t *testing.T) {
// Fri Nov 11 2022 13:52:15 GMT+0000
v := Now().UTC().
SetYear(2022).
SetMonth(time.November).
SetDay(11).
SetHour(13).
SetMinute(52).
SetSecond(15)
if v.Year() != 2022 {
t.Errorf("Expected 2022, got %d", v.Year())
}
if v.Month() != time.November {
t.Errorf("Expected November, got %s", v.Month())
}
if v.Day() != 11 {
t.Errorf("Expected 11, got %d", v.Day())
}
if v.Hour() != 13 {
t.Errorf("Expected 13, got %d", v.Hour())
}
if v.Minute() != 52 {
t.Errorf("Expected 52, got %d", v.Minute())
}
if v.Second() != 15 {
t.Errorf("Expected 15, got %d", v.Second())
}
Seoul, err := time.LoadLocation("Asia/Seoul") // "time/tzdata" is required
if err != nil {
t.Error(err)
}
v = v.In(Seoul) // Fri Nov 11 2022 22:52:15 GMT+0900 (한국 표준시)
if v.Hour() != 22 {
t.Error("Expected 22, got", v.Hour())
}
if v.Minute() != 52 {
t.Error("Expected 52, got", v.Minute())
}
if v.Second() != 15 {
t.Error("Expected 15, got", v.Second())
}
d := v.Date() // 2022-11-11
if d.Year != 2022 {
t.Error("Expected 2022, got", d.Year)
}
if d.Month != time.November {
t.Error("Expected 11, got", d.Month)
}
if d.Day != 11 {
t.Error("Expected 11, got", d.Day)
}
}