forked from dromara/carbon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
constellation.go
executable file
·243 lines (229 loc) · 4.63 KB
/
constellation.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
package carbon
import (
"strings"
)
// Constellation gets constellation name like "Aries", i18n is supported.
// 获取星座,支持i18n
func (c Carbon) Constellation() string {
if c.IsInvalid() {
return ""
}
if len(c.lang.resources) == 0 {
c.lang.SetLocale(defaultLocale)
}
index := -1
_, month, day := c.Date()
switch {
case month == 3 && day >= 21, month == 4 && day <= 19:
index = 0 // Aries
case month == 4 && day >= 20, month == 5 && day <= 20:
index = 1 // Taurus
case month == 5 && day >= 21, month == 6 && day <= 21:
index = 2 // Gemini
case month == 6 && day >= 22, month == 7 && day <= 22:
index = 3 // Cancer
case month == 7 && day >= 23, month == 8 && day <= 22:
index = 4 // Leo
case month == 8 && day >= 23, month == 9 && day <= 22:
index = 5 // Virgo
case month == 9 && day >= 23, month == 10 && day <= 23:
index = 6 // Libra
case month == 10 && day >= 24, month == 11 && day <= 22:
index = 7 // Scorpio
case month == 11 && day >= 23, month == 12 && day <= 21:
index = 8 // Sagittarius
case month == 12 && day >= 22, month == 1 && day <= 19:
index = 9 // Capricorn
case month == 1 && day >= 20, month == 2 && day <= 18:
index = 10 // Aquarius
case month == 2 && day >= 19, month == 3 && day <= 20:
index = 11 // Aquarius
}
if constellations, ok := c.lang.resources["constellations"]; ok {
slice := strings.Split(constellations, "|")
if len(slice) == 12 {
return slice[index]
}
}
return ""
}
// IsAries reports whether is Aries.
// 是否是白羊座
func (c Carbon) IsAries() bool {
if c.IsInvalid() {
return false
}
_, month, day := c.Date()
if month == 3 && day >= 21 {
return true
}
if month == 4 && day <= 19 {
return true
}
return false
}
// IsTaurus reports whether is Taurus.
// 是否是金牛座
func (c Carbon) IsTaurus() bool {
if c.IsInvalid() {
return false
}
_, month, day := c.Date()
if month == 4 && day >= 20 {
return true
}
if month == 5 && day <= 20 {
return true
}
return false
}
// IsGemini reports whether is Gemini.
// 是否是双子座
func (c Carbon) IsGemini() bool {
if c.IsInvalid() {
return false
}
_, month, day := c.Date()
if month == 5 && day >= 21 {
return true
}
if month == 6 && day <= 21 {
return true
}
return false
}
// IsCancer reports whether is Cancer.
// 是否是巨蟹座
func (c Carbon) IsCancer() bool {
if c.IsInvalid() {
return false
}
_, month, day := c.Date()
if month == 6 && day >= 22 {
return true
}
if month == 7 && day <= 22 {
return true
}
return false
}
// IsLeo reports whether is Leo.
// 是否是狮子座
func (c Carbon) IsLeo() bool {
if c.IsInvalid() {
return false
}
_, month, day := c.Date()
if month == 7 && day >= 23 {
return true
}
if month == 8 && day <= 22 {
return true
}
return false
}
// IsVirgo reports whether is Virgo.
// 是否是处女座
func (c Carbon) IsVirgo() bool {
if c.IsInvalid() {
return false
}
_, month, day := c.Date()
if month == 8 && day >= 23 {
return true
}
if month == 9 && day <= 22 {
return true
}
return false
}
// IsLibra reports whether is Libra.
// 是否是天秤座
func (c Carbon) IsLibra() bool {
if c.IsInvalid() {
return false
}
_, month, day := c.Date()
if month == 9 && day >= 23 {
return true
}
if month == 10 && day <= 23 {
return true
}
return false
}
// IsScorpio reports whether is Scorpio.
// 是否是天蝎座
func (c Carbon) IsScorpio() bool {
if c.IsInvalid() {
return false
}
_, month, day := c.Date()
if month == 10 && day >= 24 {
return true
}
if month == 11 && day <= 22 {
return true
}
return false
}
// IsSagittarius reports whether is Sagittarius.
// 是否是射手座
func (c Carbon) IsSagittarius() bool {
if c.IsInvalid() {
return false
}
_, month, day := c.Date()
if month == 11 && day >= 22 {
return true
}
if month == 12 && day <= 21 {
return true
}
return false
}
// IsCapricorn reports whether is Capricorn.
// 是否是摩羯座
func (c Carbon) IsCapricorn() bool {
if c.IsInvalid() {
return false
}
_, month, day := c.Date()
if month == 12 && day >= 22 {
return true
}
if month == 1 && day <= 19 {
return true
}
return false
}
// IsAquarius reports whether is Aquarius.
// 是否是水瓶座
func (c Carbon) IsAquarius() bool {
if c.IsInvalid() {
return false
}
_, month, day := c.Date()
if month == 1 && day >= 20 {
return true
}
if month == 2 && day <= 18 {
return true
}
return false
}
// IsPisces reports whether is Pisces.
// 是否是双鱼座
func (c Carbon) IsPisces() bool {
if c.IsInvalid() {
return false
}
_, month, day := c.Date()
if month == 2 && day >= 19 {
return true
}
if month == 3 && day <= 20 {
return true
}
return false
}