-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathchinesezodiac.go
112 lines (94 loc) · 1.6 KB
/
chinesezodiac.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
package gozodiac
import "time"
// ChineseZodiacSign represents the chinese zodiac signs
type ChineseZodiacSign int
func (s ChineseZodiacSign) String() string {
switch s {
case Monkey:
return "Monkey"
case Rooster:
return "Rooster"
case Dog:
return "Dog"
case Pig:
return "Pig"
case Rat:
return "Rat"
case Ox:
return "Ox"
case Tiger:
return "Tiger"
case Rabbit:
return "Rabbit"
case Dragon:
return "Dragon"
case Snake:
return "Snake"
case Horse:
return "Horse"
case Goat:
return "Goat"
case Error:
return "Error"
}
return ""
}
const (
// Monkey chinese zodiac sign
Monkey ChineseZodiacSign = iota
// Rooster chinese zodiac sign
Rooster
// Dog chinese zodiac sign
Dog
// Pig chinese zodiac sign
Pig
// Rat chinese zodiac sign
Rat
// Ox chinese zodiac sign
Ox
// Tiger chinese zodiac sign
Tiger
// Rabbit chinese zodiac sign
Rabbit
// Dragon chinese zodiac sign
Dragon
// Snake chinese zodiac sign
Snake
// Horse chinese zodiac sign
Horse
// Goat chinese zodiac sign
Goat
// Error is an error-case chinese zodiac sign
Error
)
// GetChineseZodiacSign returns the matching chinese zodiac sign
func GetChineseZodiacSign(date time.Time) ChineseZodiacSign {
cZodiac := int(date.Year() - ((date.Year() / 12) * 12))
switch cZodiac {
case 0:
return Monkey
case 1:
return Rooster
case 2:
return Dog
case 3:
return Pig
case 4:
return Rat
case 5:
return Ox
case 6:
return Tiger
case 7:
return Rabbit
case 8:
return Dragon
case 9:
return Snake
case 10:
return Horse
case 11:
return Goat
}
return Error // never reach here..
}