Lightweight queries
The Chinese zodiac animal, zodiac sign and Soul palace major stars, without charting the whole thing.
Some questions do not need a whole chart. These five functions each run only as far as necessary and return; their results always agree with the corresponding fields of a full chart, because they go through the same core logic.
The examples on this page all chart with Language::EnUS, so the display values in the output are
iztro's en-US vocabulary.
get_zodiac_by_solar_date
Purpose Get the Chinese zodiac animal from a solar date.
Zi Wei meaning The zodiac animal is determined by the year branch, and when the year branch
turns over is governed by year_divide.
For someone born between lunar New Year and the Beginning of Spring, the two settings give different
animals — not a bug, a difference of school.
Signature
pub fn get_zodiac_by_solar_date(
solar_date: &str,
language: Language,
config: Config,
) -> Result<String, IztroError>Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
solar_date | &str | Yes | — | Solar date in YYYY-M-D |
language | Language | Yes | — | Output language |
config | Config | Yes | — | Only year_divide affects the result |
Return value String — the animal name translated into the language.
Example
println!("{}", get_zodiac_by_solar_date("2000-8-16", Language::EnUS, Config::default())?);Output
dragonEdge cases and pitfalls
The year boundary moves with the configuration
By default the year turns over at lunar New Year. Switch to YearDivide::Exact and it turns over at
the Beginning of Spring, so people born from late January to early February can get a different
animal.
get_sign_by_solar_date / get_sign_by_lunar_date
Purpose Get the zodiac sign.
Zi Wei meaning The zodiac sign is a Western astrology concept determined solely by the solar date, unrelated to the Zi Wei algorithm. The lunar version converts to solar first, so both give the same result for the same day.
Signature
pub fn get_sign_by_solar_date(solar_date: &str, language: Language) -> Result<String, IztroError>
pub fn get_sign_by_lunar_date(
lunar_date: &str,
is_leap_month: bool,
language: Language,
) -> Result<String, IztroError>Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
solar_date / lunar_date | &str | Yes | — | The date in YYYY-M-D |
is_leap_month | bool | Yes | — | Lunar version only: whether that month is a leap month |
language | Language | Yes | — | Output language |
There is no config parameter — zodiac signs are unaffected by any setting.
Return value String.
Example
println!("{}", get_sign_by_solar_date("2000-8-16", Language::EnUS)?);
println!("{}", get_sign_by_lunar_date("2000-7-17", false, Language::EnUS)?);Output
leo
leoget_major_star_by_solar_date / get_major_star_by_lunar_date
Purpose Get just the Soul palace's major stars, without charting the whole thing.
Zi Wei meaning The major stars of the Soul palace are the single most commonly asked item in Zi Wei Dou Shu. When the Soul palace is empty, convention borrows the major stars of the opposite palace, and this function already handles that step.
Signature
pub fn get_major_star_by_solar_date(
solar_date: &str,
time_index: u8,
fix_leap: bool,
language: Language,
config: Config,
) -> Result<String, IztroError>
pub fn get_major_star_by_lunar_date(
lunar_date: &str,
time_index: u8,
leap: LeapMonth,
language: Language,
config: Config,
) -> Result<String, IztroError>Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
solar_date / lunar_date | &str | Yes | — | The date |
time_index | u8 | Yes | — | Hour index 0–12; the Soul palace is fixed jointly by month and hour |
fix_leap | bool | Yes | — | Solar version only: whether a solar date falling after the 15th of a leap month is treated as the next month |
leap | LeapMonth | Yes | — | Lunar version only: NotLeap / Leap / LeapFixed, see by_lunar |
language | Language | Yes | — | Output language |
config | Config | Yes | — | Charting configuration |
Return value String — several major stars separated by commas; the opposite palace's major
stars when the Soul palace is empty.
Rust names these two functions in the singular, matching iztro, even though the Soul palace can hold
more than one major star. The plural get_major_stars on
Star placement is a
different function: it returns the distribution across all twelve palaces.
Example
let cfg = Config::default();
println!("{}", get_major_star_by_solar_date("2000-8-16", 2, true, Language::EnUS, cfg.clone())?);
println!("{}", get_major_star_by_solar_date("2000-8-16", 2, true, Language::ZhCN, cfg.clone())?);Output
emperor
紫微Edge cases and pitfalls
major_star_keys_of_soul_palace
Purpose The Soul palace's major stars as language-independent keys — the key form of the two functions above, for programmatic checks.
Signature
pub fn major_star_keys_of_soul_palace(astrolabe: &Astrolabe) -> Vec<String>Takes an already-cast chart (pair it with by_solar / by_lunar); the borrowing rule shares one
implementation with the translated form: an empty Soul palace borrows its opposite's major stars,
and an empty list comes back when the opposite has none either. Keys are independent of the chart
language.
Example
let chart = by_solar("2000-8-16", 2, Gender::Female, true, Language::EnUS, Config::default())?;
println!("{:?}", major_star_keys_of_soul_palace(&chart));Output
["ziweiMaj"]