carbon/calendar.go

133 lines
2.4 KiB
Go
Raw Normal View History

2020-10-01 03:32:03 +08:00
package carbon
2020-10-01 14:35:56 +08:00
var (
// 十二生肖
2020-10-10 16:11:22 +08:00
SymbolicAnimals = [12]string{"猴", "鸡", "狗", "猪", "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊"}
2020-10-01 14:35:56 +08:00
// 天干
HeavenlyStems = [10]string{"庚", "辛", "壬", "癸", "甲", "乙", "丙", "丙", "戊", "己"}
// 地支
EarthlyBranches = [12]string{"申", "酉", "戌", "亥", "子", "丑", "寅", "卯", "辰", "巳", "午", "未"}
)
// ToAnimalYear 获取生肖年
2020-10-10 16:11:22 +08:00
func (c Carbon) ToAnimalYear() string {
2020-10-01 03:32:03 +08:00
year := c.Time.Year()
2020-10-01 14:35:56 +08:00
return SymbolicAnimals[year%12]
}
// ToLunarYear 获取农历年
2020-10-10 16:11:22 +08:00
func (c Carbon) ToLunarYear() string {
2020-10-01 14:35:56 +08:00
year := c.Time.Year()
return HeavenlyStems[year%10] + EarthlyBranches[year%12]
2020-10-01 03:32:03 +08:00
}
2020-10-01 14:35:56 +08:00
// IsYearOfRat 是否是鼠年
2020-10-10 16:11:22 +08:00
func (c Carbon) IsYearOfRat() bool {
2020-10-01 03:32:03 +08:00
year := c.Time.Year()
if year%12 == 4 {
return true
}
return false
}
2020-10-01 14:35:56 +08:00
// IsYearOfOx 是否是牛年
2020-10-10 16:11:22 +08:00
func (c Carbon) IsYearOfOx() bool {
2020-10-01 03:32:03 +08:00
year := c.Time.Year()
if year%12 == 5 {
return true
}
return false
}
2020-10-01 14:35:56 +08:00
// IsYearOfTiger 是否是虎年
2020-10-10 16:11:22 +08:00
func (c Carbon) IsYearOfTiger() bool {
2020-10-01 03:32:03 +08:00
year := c.Time.Year()
if year%12 == 6 {
return true
}
return false
}
2020-10-01 14:35:56 +08:00
// IsYearOfRabbit 是否是兔年
2020-10-10 16:11:22 +08:00
func (c Carbon) IsYearOfRabbit() bool {
2020-10-01 03:32:03 +08:00
year := c.Time.Year()
if year%12 == 7 {
return true
}
return false
}
2020-10-01 14:35:56 +08:00
// IsYearOfDragon 是否是龙年
2020-10-10 16:11:22 +08:00
func (c Carbon) IsYearOfDragon() bool {
2020-10-01 03:32:03 +08:00
year := c.Time.Year()
2020-10-10 16:11:22 +08:00
if year%12 == 8 {
2020-10-01 03:32:03 +08:00
return true
}
return false
}
2020-10-01 14:35:56 +08:00
// IsYearOfSnake 是否是蛇年
2020-10-10 16:11:22 +08:00
func (c Carbon) IsYearOfSnake() bool {
2020-10-01 03:32:03 +08:00
year := c.Time.Year()
if year%12 == 9 {
return true
}
return false
}
2020-10-01 14:35:56 +08:00
// IsYearOfHorse 是否是马年
2020-10-10 16:11:22 +08:00
func (c Carbon) IsYearOfHorse() bool {
2020-10-01 03:32:03 +08:00
year := c.Time.Year()
if year%12 == 10 {
return true
}
return false
}
2020-10-01 14:35:56 +08:00
// IsYearOfGoat 是否是羊年
2020-10-10 16:11:22 +08:00
func (c Carbon) IsYearOfGoat() bool {
2020-10-01 03:32:03 +08:00
year := c.Time.Year()
if year%12 == 11 {
return true
}
return false
}
2020-10-01 17:39:15 +08:00
// IsYearOfMonkey 是否是猴年
2020-10-10 16:11:22 +08:00
func (c Carbon) IsYearOfMonkey() bool {
2020-10-01 17:39:15 +08:00
year := c.Time.Year()
if year%12 == 0 {
return true
}
return false
}
// IsYearOfRooster 是否是鸡年
2020-10-10 16:11:22 +08:00
func (c Carbon) IsYearOfRooster() bool {
2020-10-01 17:39:15 +08:00
year := c.Time.Year()
if year%12 == 1 {
return true
}
return false
}
// IsYearOfDog 是否是狗年
2020-10-10 16:11:22 +08:00
func (c Carbon) IsYearOfDog() bool {
2020-10-01 17:39:15 +08:00
year := c.Time.Year()
if year%12 == 2 {
return true
}
return false
}
// IsYearOfPig 是否是猪年
2020-10-10 16:11:22 +08:00
func (c Carbon) IsYearOfPig() bool {
2020-10-01 17:39:15 +08:00
year := c.Time.Year()
if year%12 == 3 {
return true
}
return false
}