forked from XieWeiXie/holidays
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlunar_holiday.go
110 lines (99 loc) · 2.5 KB
/
lunar_holiday.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
package holidays
import "time"
type Traditional struct {
Name string
Detail string
}
func (l Traditional) Desc() string {
return l.Name
}
func (l Traditional) When() string {
return l.Detail
}
type TraditionalDay interface {
When() string
Desc() string
}
var (
chineseNewYear Traditional = Traditional{
Name: "Chinese New Year(新年)",
Detail: "1st - 15th of the first lunar month",
}
lanternFestival Traditional = Traditional{
Name: "LanternFestival(元宵节)",
Detail: "15th day of the first lunar month",
}
qingMingFestival Traditional = Traditional{
Name: "Qingming Festival(清明节)",
Detail: "April 4th or 5th of the solar calendar",
}
dragonBoatFestival Traditional = Traditional{
Name: "Dragon Boat Festival(端午节)",
Detail: "5th day of the 5th lunar month",
}
doubleSeventhDay Traditional = Traditional{
Name: "Double Seventh Festival(七夕节)",
Detail: "7th day of seventh lunar month",
}
midAutumnDay Traditional = Traditional{
Name: "Mid-Autumn Festival(中秋节)",
Detail: "15th of the 8th lunar month",
}
doubleNinthDay Traditional = Traditional{
Name: "Double Ninth Festival(重阳节)",
Detail: "9th day of the 9th lunar month",
}
winterSolstice Traditional = Traditional{
Name: "Winter Solstice(冬至)",
Detail: "Dec.21st,22nd or 23rd in solar month",
}
labaFestival Traditional = Traditional{
Name: "Laba Festival(腊八节)",
Detail: "8th day of the 12th lunar month",
}
)
type lunar struct {
Days []TraditionalDay
}
func (l lunar) TraditionDays() []TraditionalDay {
return l.Days
}
func (l lunar) GuessWithMonth(month int) []TraditionalDay {
switch time.Month(month) {
case time.January:
return []TraditionalDay{chineseNewYear, lanternFestival}
case time.April:
return []TraditionalDay{qingMingFestival}
case time.May:
return []TraditionalDay{dragonBoatFestival}
case time.June:
return []TraditionalDay{doubleSeventhDay}
case time.August:
return []TraditionalDay{midAutumnDay}
case time.September:
return []TraditionalDay{doubleNinthDay}
case time.December:
return []TraditionalDay{winterSolstice, labaFestival}
default:
return nil
}
}
func (l lunar) CurrentMonth() []TraditionalDay {
month := time.Now().Month()
return l.GuessWithMonth(int(month))
}
func LunarDay() lunar {
return lunar{
Days: []TraditionalDay{
chineseNewYear,
lanternFestival,
qingMingFestival,
dragonBoatFestival,
doubleSeventhDay,
midAutumnDay,
doubleNinthDay,
winterSolstice,
labaFestival,
},
}
}