-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathholiday_test.go
137 lines (112 loc) · 3.63 KB
/
holiday_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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package jpholiday
import (
"testing"
"time"
)
func TestIsJapanHoliday(t *testing.T) {
jst, _ := time.LoadLocation("Asia/Tokyo")
// 1954-12-31 is out of service
if IsJapanHoliday(time.Date(1954, 12, 31, 0, 0, 0, 0, jst)) {
t.Errorf("1954-12-31 is not a holiday")
}
// 1955-01-01 is a holiday
if !IsJapanHoliday(time.Date(1955, 1, 1, 0, 0, 0, 0, jst)) {
t.Errorf("1955-01-01 is a holiday")
}
// 1972-5-5 is a holiday
if !IsJapanHoliday(time.Date(1972, 5, 5, 0, 0, 0, 0, jst)) {
t.Errorf("1972-5-5 is a holiday")
}
// 1991-7-4 is not a holiday
if IsJapanHoliday(time.Date(1991, 7, 4, 0, 0, 0, 0, jst)) {
t.Errorf("1991-7-4 is not a holiday")
}
// 2025-11-24 is a holiday
if !IsJapanHoliday(time.Date(2025, 11, 24, 0, 0, 0, 0, jst)) {
t.Errorf("2025-11-24 is a holiday")
}
// 2025-11-25 is not a holiday
if IsJapanHoliday(time.Date(2025, 11, 25, 0, 0, 0, 0, jst)) {
t.Errorf("2025-11-25 is not a holiday")
}
utc, _ := time.LoadLocation("UTC")
// 1954-12-31 14:59:59:999 (UTC) is out of service
if IsJapanHoliday(time.Date(1954, 12, 31, 15, 0, 0, 0, utc).Add(-1)) {
t.Errorf("1954-12-31 14:59:59 (UTC) is not a holiday")
}
// 1954-12-31 15:00:00:000 (UTC) is a holiday
if !IsJapanHoliday(time.Date(1954, 12, 31, 15, 0, 0, 0, utc)) {
t.Errorf("1954-12-31 15:00:00 (UTC) is a holiday")
}
// 1955-01-01 14:59:59:999 (UTC) is a holiday
if !IsJapanHoliday(time.Date(1955, 1, 1, 15, 0, 0, 0, utc).Add(-1)) {
t.Errorf("1955-01-01 14:59:59 (UTC) is a holiday")
}
// 1955-01-01 15:00:00:000 (UTC) is not a holiday
if IsJapanHoliday(time.Date(1955, 1, 1, 15, 0, 0, 0, utc)) {
t.Errorf("1955-01-01 15:00:00 (UTC) is not a holiday")
}
}
func Test_GetJapanHolidayName(t *testing.T) {
jst, _ := time.LoadLocation("Asia/Tokyo")
// 1954-12-31 is out of service
_, ok := GetJapanHolidayName(time.Date(1954, 12, 31, 0, 0, 0, 0, jst))
if ok {
t.Errorf("1954-12-31 is not a holiday")
}
// 1955-01-01 is a holiday
name, ok := GetJapanHolidayName(time.Date(1955, 1, 1, 0, 0, 0, 0, jst))
if !ok {
t.Errorf("1955-01-01 is a holiday")
}
if name != "元日" {
t.Errorf("1955-01-01 is 元日")
}
// 1972-5-5 is a holiday
name, ok = GetJapanHolidayName(time.Date(1972, 5, 5, 0, 0, 0, 0, jst))
if !ok {
t.Errorf("1972-5-5 is a holiday")
}
if name != "こどもの日" {
t.Errorf("1972-5-5 is こどもの日")
}
// 1991-7-4 is not a holiday
_, ok = GetJapanHolidayName(time.Date(1991, 7, 4, 0, 0, 0, 0, jst))
if ok {
t.Errorf("1991-7-4 is not a holiday")
}
// 2025-11-24 is a holiday
name, ok = GetJapanHolidayName(time.Date(2025, 11, 24, 0, 0, 0, 0, jst))
if !ok {
t.Errorf("2025-11-24 is a holiday")
}
if name != "休日" {
t.Errorf("2025-11-24 is 休日")
}
// 2025-11-25 is not a holiday
_, ok = GetJapanHolidayName(time.Date(2025, 11, 25, 0, 0, 0, 0, jst))
if ok {
t.Errorf("2025-11-25 is not a holiday")
}
utc, _ := time.LoadLocation("UTC")
// 1954-12-31 14:59:59:999 (UTC) is out of service
_, ok = GetJapanHolidayName(time.Date(1954, 12, 31, 15, 0, 0, 0, utc).Add(-1))
if ok {
t.Errorf("1954-12-31 14:59:59 (UTC) is not a holiday")
}
// 1954-12-31 15:00:00:000 (UTC) is a holiday
name, ok = GetJapanHolidayName(time.Date(1954, 12, 31, 15, 0, 0, 0, utc))
if !ok {
t.Errorf("1954-12-31 15:00:00 (UTC) is a holiday")
}
// 1955-01-01 14:59:59:999 (UTC) is a holiday
name, ok = GetJapanHolidayName(time.Date(1955, 1, 1, 15, 0, 0, 0, utc).Add(-1))
if !ok {
t.Errorf("1955-01-01 14:59:59 (UTC) is a holiday")
}
// 1955-01-01 15:00:00:000 (UTC) is not a holiday
_, ok = GetJapanHolidayName(time.Date(1955, 1, 1, 15, 0, 0, 0, utc))
if ok {
t.Errorf("1955-01-01 15:00:00 (UTC) is not a holiday")
}
}