carbon/constellation.go

244 lines
4.6 KiB
Go
Raw Normal View History

2021-02-23 09:32:55 +08:00
package carbon
2021-08-05 19:39:19 +08:00
import (
"strings"
)
2021-02-23 09:32:55 +08:00
2022-04-14 10:43:07 +08:00
// Constellation gets constellation name like "Aries", i18n is supported.
2021-07-28 15:18:05 +08:00
// 获取星座支持i18n
2021-02-23 09:32:55 +08:00
func (c Carbon) Constellation() string {
2021-07-23 10:55:38 +08:00
if c.IsInvalid() {
2021-02-23 09:32:55 +08:00
return ""
}
if len(c.lang.resources) == 0 {
c.lang.SetLocale(defaultLocale)
2021-02-23 09:32:55 +08:00
}
index := -1
2022-04-12 17:17:31 +08:00
_, month, day := c.Date()
2021-02-23 09:32:55 +08:00
switch {
2022-04-12 17:17:31 +08:00
case month == 3 && day >= 21, month == 4 && day <= 19:
2022-04-21 15:04:31 +08:00
index = 0 // Aries
2022-04-12 17:17:31 +08:00
case month == 4 && day >= 20, month == 5 && day <= 20:
2022-04-21 15:04:31 +08:00
index = 1 // Taurus
2022-04-12 17:17:31 +08:00
case month == 5 && day >= 21, month == 6 && day <= 21:
2022-04-21 15:04:31 +08:00
index = 2 // Gemini
2022-04-12 17:17:31 +08:00
case month == 6 && day >= 22, month == 7 && day <= 22:
2022-04-21 15:04:31 +08:00
index = 3 // Cancer
2022-04-12 17:17:31 +08:00
case month == 7 && day >= 23, month == 8 && day <= 22:
2022-04-21 15:04:31 +08:00
index = 4 // Leo
2022-04-12 17:17:31 +08:00
case month == 8 && day >= 23, month == 9 && day <= 22:
2022-04-21 15:04:31 +08:00
index = 5 // Virgo
2022-04-12 17:17:31 +08:00
case month == 9 && day >= 23, month == 10 && day <= 23:
2022-04-21 15:04:31 +08:00
index = 6 // Libra
2022-04-12 17:17:31 +08:00
case month == 10 && day >= 24, month == 11 && day <= 22:
2022-04-21 15:04:31 +08:00
index = 7 // Scorpio
2022-04-12 17:17:31 +08:00
case month == 11 && day >= 23, month == 12 && day <= 21:
2022-04-21 15:04:31 +08:00
index = 8 // Sagittarius
2022-04-12 17:17:31 +08:00
case month == 12 && day >= 22, month == 1 && day <= 19:
2022-04-21 15:04:31 +08:00
index = 9 // Capricorn
2022-04-12 17:17:31 +08:00
case month == 1 && day >= 20, month == 2 && day <= 18:
2022-04-21 15:04:31 +08:00
index = 10 // Aquarius
2022-04-12 17:17:31 +08:00
case month == 2 && day >= 19, month == 3 && day <= 20:
2022-04-21 15:04:31 +08:00
index = 11 // Aquarius
2021-02-23 09:32:55 +08:00
}
if constellations, ok := c.lang.resources["constellations"]; ok {
2021-02-23 09:32:55 +08:00
slice := strings.Split(constellations, "|")
2021-08-02 10:22:23 +08:00
if len(slice) == 12 {
return slice[index]
}
2021-02-23 09:32:55 +08:00
}
return ""
}
2021-09-16 09:52:35 +08:00
// IsAries reports whether is Aries.
2021-07-28 15:18:05 +08:00
// 是否是白羊座
2021-02-23 09:32:55 +08:00
func (c Carbon) IsAries() bool {
2021-07-23 10:55:38 +08:00
if c.IsInvalid() {
2021-07-09 15:12:20 +08:00
return false
}
2022-04-12 17:17:31 +08:00
_, month, day := c.Date()
if month == 3 && day >= 21 {
2021-02-23 09:32:55 +08:00
return true
}
2022-04-12 17:17:31 +08:00
if month == 4 && day <= 19 {
2021-02-23 09:32:55 +08:00
return true
}
return false
}
2021-09-16 09:52:35 +08:00
// IsTaurus reports whether is Taurus.
2021-07-28 15:18:05 +08:00
// 是否是金牛座
2021-02-23 09:32:55 +08:00
func (c Carbon) IsTaurus() bool {
2021-07-23 10:55:38 +08:00
if c.IsInvalid() {
2021-07-09 15:12:20 +08:00
return false
}
2022-04-12 17:17:31 +08:00
_, month, day := c.Date()
if month == 4 && day >= 20 {
2021-02-23 09:32:55 +08:00
return true
}
2022-04-12 17:17:31 +08:00
if month == 5 && day <= 20 {
2021-02-23 09:32:55 +08:00
return true
}
return false
}
2021-09-16 09:52:35 +08:00
// IsGemini reports whether is Gemini.
2021-07-28 15:18:05 +08:00
// 是否是双子座
2021-02-23 09:32:55 +08:00
func (c Carbon) IsGemini() bool {
2021-07-23 10:55:38 +08:00
if c.IsInvalid() {
2021-07-09 15:12:20 +08:00
return false
}
2022-04-12 17:17:31 +08:00
_, month, day := c.Date()
if month == 5 && day >= 21 {
2021-02-23 09:32:55 +08:00
return true
}
2022-04-12 17:17:31 +08:00
if month == 6 && day <= 21 {
2021-02-23 09:32:55 +08:00
return true
}
return false
}
2021-09-16 09:52:35 +08:00
// IsCancer reports whether is Cancer.
2021-07-28 15:18:05 +08:00
// 是否是巨蟹座
2021-02-23 09:32:55 +08:00
func (c Carbon) IsCancer() bool {
2021-07-23 10:55:38 +08:00
if c.IsInvalid() {
2021-07-09 15:12:20 +08:00
return false
}
2022-04-12 17:17:31 +08:00
_, month, day := c.Date()
if month == 6 && day >= 22 {
2021-02-23 09:32:55 +08:00
return true
}
2022-04-12 17:17:31 +08:00
if month == 7 && day <= 22 {
2021-02-23 09:32:55 +08:00
return true
}
return false
}
2021-09-16 09:52:35 +08:00
// IsLeo reports whether is Leo.
2021-07-28 15:18:05 +08:00
// 是否是狮子座
2021-02-23 09:32:55 +08:00
func (c Carbon) IsLeo() bool {
2021-07-23 10:55:38 +08:00
if c.IsInvalid() {
2021-07-09 15:12:20 +08:00
return false
}
2022-04-12 17:17:31 +08:00
_, month, day := c.Date()
if month == 7 && day >= 23 {
2021-02-23 09:32:55 +08:00
return true
}
2022-04-12 17:17:31 +08:00
if month == 8 && day <= 22 {
2021-02-23 09:32:55 +08:00
return true
}
return false
}
2021-09-16 09:52:35 +08:00
// IsVirgo reports whether is Virgo.
2021-07-28 15:18:05 +08:00
// 是否是处女座
2021-02-23 09:32:55 +08:00
func (c Carbon) IsVirgo() bool {
2021-07-23 10:55:38 +08:00
if c.IsInvalid() {
2021-07-09 15:12:20 +08:00
return false
}
2022-04-12 17:17:31 +08:00
_, month, day := c.Date()
if month == 8 && day >= 23 {
2021-02-23 09:32:55 +08:00
return true
}
2022-04-12 17:17:31 +08:00
if month == 9 && day <= 22 {
2021-02-23 09:32:55 +08:00
return true
}
return false
}
2021-09-16 09:52:35 +08:00
// IsLibra reports whether is Libra.
2021-07-28 15:18:05 +08:00
// 是否是天秤座
2021-02-23 09:32:55 +08:00
func (c Carbon) IsLibra() bool {
2021-07-23 10:55:38 +08:00
if c.IsInvalid() {
2021-07-09 15:12:20 +08:00
return false
}
2022-04-12 17:17:31 +08:00
_, month, day := c.Date()
if month == 9 && day >= 23 {
2021-02-23 09:32:55 +08:00
return true
}
2022-04-12 17:17:31 +08:00
if month == 10 && day <= 23 {
2021-02-23 09:32:55 +08:00
return true
}
return false
}
2021-09-16 09:52:35 +08:00
// IsScorpio reports whether is Scorpio.
2021-07-28 15:18:05 +08:00
// 是否是天蝎座
2021-02-23 09:32:55 +08:00
func (c Carbon) IsScorpio() bool {
2021-07-23 10:55:38 +08:00
if c.IsInvalid() {
2021-07-09 15:12:20 +08:00
return false
}
2022-04-12 17:17:31 +08:00
_, month, day := c.Date()
if month == 10 && day >= 24 {
2021-02-23 09:32:55 +08:00
return true
}
2022-04-12 17:17:31 +08:00
if month == 11 && day <= 22 {
2021-02-23 09:32:55 +08:00
return true
}
return false
}
2021-09-16 09:52:35 +08:00
// IsSagittarius reports whether is Sagittarius.
2021-07-28 15:18:05 +08:00
// 是否是射手座
2021-02-23 09:32:55 +08:00
func (c Carbon) IsSagittarius() bool {
2021-07-23 10:55:38 +08:00
if c.IsInvalid() {
2021-07-09 15:12:20 +08:00
return false
}
2022-04-12 17:17:31 +08:00
_, month, day := c.Date()
if month == 11 && day >= 22 {
2021-02-23 09:32:55 +08:00
return true
}
2022-04-12 17:17:31 +08:00
if month == 12 && day <= 21 {
2021-02-23 09:32:55 +08:00
return true
}
return false
}
2021-09-16 09:52:35 +08:00
// IsCapricorn reports whether is Capricorn.
2021-07-28 15:18:05 +08:00
// 是否是摩羯座
2021-02-23 09:32:55 +08:00
func (c Carbon) IsCapricorn() bool {
2021-07-23 10:55:38 +08:00
if c.IsInvalid() {
2021-07-09 15:12:20 +08:00
return false
}
2022-04-12 17:17:31 +08:00
_, month, day := c.Date()
if month == 12 && day >= 22 {
2021-02-23 09:32:55 +08:00
return true
}
2022-04-12 17:17:31 +08:00
if month == 1 && day <= 19 {
2021-02-23 09:32:55 +08:00
return true
}
return false
}
2021-09-16 09:52:35 +08:00
// IsAquarius reports whether is Aquarius.
2021-07-28 15:18:05 +08:00
// 是否是水瓶座
2021-02-23 09:32:55 +08:00
func (c Carbon) IsAquarius() bool {
2021-07-23 10:55:38 +08:00
if c.IsInvalid() {
2021-07-09 15:12:20 +08:00
return false
}
2022-04-12 17:17:31 +08:00
_, month, day := c.Date()
if month == 1 && day >= 20 {
2021-02-23 09:32:55 +08:00
return true
}
2022-04-12 17:17:31 +08:00
if month == 2 && day <= 18 {
2021-02-23 09:32:55 +08:00
return true
}
return false
}
2021-09-16 09:52:35 +08:00
// IsPisces reports whether is Pisces.
2021-07-28 15:18:05 +08:00
// 是否是双鱼座
2021-02-23 09:32:55 +08:00
func (c Carbon) IsPisces() bool {
2021-07-23 10:55:38 +08:00
if c.IsInvalid() {
2021-07-09 15:12:20 +08:00
return false
}
2022-04-12 17:17:31 +08:00
_, month, day := c.Date()
if month == 2 && day >= 19 {
2021-02-23 09:32:55 +08:00
return true
}
2022-04-12 17:17:31 +08:00
if month == 3 && day <= 20 {
2021-02-23 09:32:55 +08:00
return true
}
return false
}