carbon/constellation.go

231 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
2021-07-28 15:18:05 +08:00
// Constellation get constellation name, i18n is supported
// 获取星座支持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 ""
}
2021-07-19 09:49:56 +08:00
if len(c.Lang.resources) == 0 {
c.Lang.SetLocale(defaultLocale)
2021-02-23 09:32:55 +08:00
}
index := -1
switch {
case c.Month() == 3 && c.Day() >= 21, c.Month() == 4 && c.Day() <= 19:
index = 0 // 白羊座
case c.Month() == 4 && c.Day() >= 20, c.Month() == 5 && c.Day() <= 20:
index = 1 // 金牛座
case c.Month() == 5 && c.Day() >= 21, c.Month() == 6 && c.Day() <= 21:
index = 2 // 双子座
case c.Month() == 6 && c.Day() >= 22, c.Month() == 7 && c.Day() <= 22:
index = 3 // 巨蟹座
case c.Month() == 7 && c.Day() >= 23, c.Month() == 8 && c.Day() <= 22:
index = 4 // 狮子座
case c.Month() == 8 && c.Day() >= 23, c.Month() == 9 && c.Day() <= 22:
index = 5 // 处女座
case c.Month() == 9 && c.Day() >= 23, c.Month() == 10 && c.Day() <= 23:
index = 6 // 天秤座
case c.Month() == 10 && c.Day() >= 24, c.Month() == 11 && c.Day() <= 22:
index = 7 // 天蝎座
case c.Month() == 11 && c.Day() >= 23, c.Month() == 12 && c.Day() <= 21:
index = 8 // 射手座
case c.Month() == 12 && c.Day() >= 22, c.Month() == 1 && c.Day() <= 19:
index = 9 // 摩羯座
case c.Month() == 1 && c.Day() >= 20, c.Month() == 2 && c.Day() <= 18:
index = 10 // 水瓶座
case c.Month() == 2 && c.Day() >= 19, c.Month() == 3 && c.Day() <= 20:
index = 11 // 双鱼座
}
if constellations, ok := c.Lang.resources["constellations"]; ok {
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-07-31 13:25:52 +08:00
// IsAries 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
}
2021-02-23 09:32:55 +08:00
if c.Month() == 3 && c.Day() >= 21 {
return true
}
if c.Month() == 4 && c.Day() <= 19 {
return true
}
return false
}
2021-07-28 15:18:05 +08:00
// IsTaurus whether is Taurus
// 是否是金牛座
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
}
2021-02-23 09:32:55 +08:00
if c.Month() == 4 && c.Day() >= 20 {
return true
}
if c.Month() == 5 && c.Day() <= 20 {
return true
}
return false
}
2021-07-28 15:18:05 +08:00
// IsGemini whether is Gemini
// 是否是双子座
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
}
2021-02-23 09:32:55 +08:00
if c.Month() == 5 && c.Day() >= 21 {
return true
}
if c.Month() == 6 && c.Day() <= 21 {
return true
}
return false
}
2021-07-28 15:18:05 +08:00
// IsCancer whether is Cancer
// 是否是巨蟹座
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
}
2021-02-23 09:32:55 +08:00
if c.Month() == 6 && c.Day() >= 22 {
return true
}
if c.Month() == 7 && c.Day() <= 22 {
return true
}
return false
}
2021-07-28 15:18:05 +08:00
// IsLeo whether is Leo
// 是否是狮子座
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
}
2021-02-23 09:32:55 +08:00
if c.Month() == 7 && c.Day() >= 23 {
return true
}
if c.Month() == 8 && c.Day() <= 22 {
return true
}
return false
}
2021-07-28 15:18:05 +08:00
// IsVirgo whether is Virgo
// 是否是处女座
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
}
2021-02-23 09:32:55 +08:00
if c.Month() == 8 && c.Day() >= 23 {
return true
}
if c.Month() == 9 && c.Day() <= 22 {
return true
}
return false
}
2021-07-28 15:18:05 +08:00
// IsLibra whether is Libra
// 是否是天秤座
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
}
2021-02-23 09:32:55 +08:00
if c.Month() == 9 && c.Day() >= 23 {
return true
}
if c.Month() == 10 && c.Day() <= 23 {
return true
}
return false
}
2021-07-28 15:18:05 +08:00
// IsScorpio whether is Scorpio
// 是否是天蝎座
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
}
2021-02-23 09:32:55 +08:00
if c.Month() == 10 && c.Day() >= 24 {
return true
}
if c.Month() == 11 && c.Day() <= 22 {
return true
}
return false
}
2021-07-28 15:18:05 +08:00
// IsSagittarius whether is Sagittarius
// 是否是射手座
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
}
2021-02-23 09:32:55 +08:00
if c.Month() == 11 && c.Day() >= 22 {
return true
}
if c.Month() == 12 && c.Day() <= 21 {
return true
}
return false
}
2021-07-28 15:18:05 +08:00
// IsCapricorn whether is Capricorn
// 是否是摩羯座
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
}
2021-02-23 09:32:55 +08:00
if c.Month() == 12 && c.Day() >= 22 {
return true
}
if c.Month() == 1 && c.Day() <= 19 {
return true
}
return false
}
2021-07-28 15:18:05 +08:00
// IsAquarius whether is Aquarius
// 是否是水瓶座
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
}
2021-02-23 09:32:55 +08:00
if c.Month() == 1 && c.Day() >= 20 {
return true
}
if c.Month() == 2 && c.Day() <= 18 {
return true
}
return false
}
2021-07-28 15:18:05 +08:00
// IsPisces whether is Pisces
// 是否是双鱼座
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
}
2021-02-23 09:32:55 +08:00
if c.Month() == 2 && c.Day() >= 19 {
return true
}
if c.Month() == 3 && c.Day() <= 20 {
return true
}
return false
}