轻量查询

不排整盘就能拿到的生肖、星座与命宫主星。

有些问题不需要整张星盘。这五个函数各自只跑到必要的那一步就返回, 结果与完整排盘的对应字段永远一致——它们走的是同一套核心逻辑。

本页示例统一用 "zh-CN" 排盘,因此输出里的展示值都是中文。


GetZodiacBySolarDate

用途 由公历日期取生肖。

斗数含义 生肖由年支决定,而年支的换算时点受 YearDivide 影响。 正月初一与立春之间出生的人,两种配置会得到不同的生肖——这不是缺陷,是流派差异。

签名

func GetZodiacBySolarDate(solarDate string, language Language, config *Config) (string, error)

参数

参数类型必填默认说明
solarDatestring公历日期,格式 YYYY-M-D
languageLanguage盘面语言
config*Confignil 取默认;仅 YearDivide 影响结果

返回值 按语言翻译的生肖名。

示例

zodiac, _ := iztro.GetZodiacBySolarDate("2000-8-16", iztro.LanguageZhCN, nil)
fmt.Println(zodiac)

输出

边界与陷阱

跨年边界会随配置改变

默认按正月初一换年。改成 &Config{YearDivide: iztro.YearDivideExact} 后按立春换年, 1 月下旬到 2 月上旬出生的人可能拿到不同生肖。


GetSignBySolarDate / GetSignByLunarDate

用途 取星座。

斗数含义 星座是西洋占星概念,只由公历日期决定,与斗数算法无关。 农历版本先把农历转成公历再判定,因此两者对同一天的结果相同。

签名

func GetSignBySolarDate(solarDate string, language Language) (string, error)
func GetSignByLunarDate(lunarDate string, isLeapMonth bool, language Language) (string, error)

参数

参数类型必填默认说明
solarDate / lunarDatestring日期,格式 YYYY-M-D
isLeapMonthbool仅农历版本:该月是否闰月
languageLanguage盘面语言

config 参数——星座不受任何配置影响。

返回值 星座名。

示例

s1, _ := iztro.GetSignBySolarDate("2000-8-16", iztro.LanguageZhCN)
s2, _ := iztro.GetSignByLunarDate("2000-7-17", false, iztro.LanguageZhCN)

fmt.Println(s1, s2)

输出

狮子座 狮子座

GetMajorStarBySolarDate / GetMajorStarByLunarDate

用途 只取命宫主星,不排整盘。

斗数含义 命宫主星是斗数最常被单独问起的一项。 命宫为空宫时按惯例借对宫主星来看,本函数已经处理了这一步。

签名

func GetMajorStarBySolarDate(
    solarDate string, timeIndex uint8, fixLeap bool, language Language, config *Config,
) (string, error)

func GetMajorStarByLunarDate(
    lunarDate string, timeIndex uint8, leap LeapMonth, language Language, config *Config,
) (string, error)

参数

参数类型必填默认说明
solarDate / lunarDatestring日期
timeIndexuint8时辰索引 0–12,命宫由月份与时辰共同决定
fixLeapbool仅阳历版本:阳历日期落在闰月十五之后时是否视作次月
leapLeapMonth仅农历版本:NotLeapMonth / LeapMonthKeep / LeapMonthFixed,见 ByLunar
languageLanguage盘面语言
config*Confignil 取默认

返回值 多颗主星以逗号分隔;空宫时返回对宫主星。

示例

zh, _ := iztro.GetMajorStarBySolarDate("2000-8-16", 2, true, iztro.LanguageZhCN, nil)
en, _ := iztro.GetMajorStarBySolarDate("2000-8-16", 2, true, iztro.LanguageEnUS, nil)

fmt.Println(zh, en)

输出

紫微 emperor

边界与陷阱

本页目录