Crate chinese_lunisolar_calendar

Source
Expand description

§Chinese Lunisolar Calendar

The traditional Chinese Calendar, known as 農曆 or 陰曆 in Chinese, is based on the moon, and is commonly referred to as the Lunar Calendar.

Due to the Lunar Calendar’s 60-year cycle and the absence of regular rules for the days in each lunar month, as well as the variable number of months in a lunar year, using the Lunar Calendar without referencing other calendars can be challenging. The Lunisolar Calendar is designed to address this issue by combining both the Solar Calendar (Gregorian Calendar) and the Lunar Calendar, ensuring accuracy, predictability, and practicality.

This library allows you to seamlessly convert dates between the Lunisolar Calendar and the Solar Calendar, compute the Ba Zi (八字) weight, and also convert dates to Chinese text strings. Furthermore, it enables parsing of Chinese text strings into dates in both Simplified Chinese and Traditional Chinese.

§Examples

use chinese_lunisolar_calendar::SolarDate;

let solar_date = SolarDate::from_ymd(2019, 1, 15).unwrap();

assert_eq!("二〇一九年一月十五日", solar_date.to_string());
use chinese_lunisolar_calendar::{LunisolarDate, SolarDate};

let lunisolar_date = LunisolarDate::from_solar_date(SolarDate::from_ymd(2019, 1, 15).unwrap()).unwrap();

assert_eq!("二〇一八 戊戌、狗年 臘月 初十", lunisolar_date.to_string());

assert_eq!("二〇一八 戊戌、狗年 臘月 初十", format!("{lunisolar_date}"));
assert_eq!("二〇一八 戊戌、狗年 腊月 初十", format!("{lunisolar_date:#}"));

use chinese_lunisolar_calendar::EarthlyBranch;
assert_eq!(43, lunisolar_date.get_ba_zi_weight(EarthlyBranch::Ninth));

To calculate the Ba Zi weight, the ba-zi-weight feature must be enabled.

§No Std

Disable the default features to compile this crate without std.

[dependencies.chinese-lunisolar-calendar]
version = "*"
default-features = false

Re-exports§

pub extern crate chrono;

Structs§

LunarDayError
錯誤的農曆日。
LunarMonthError
錯誤的農曆月。
LunarYear
農曆年份,由天干加地支組成,六十年一輪。
LunarYearError
錯誤的農曆年。
LunisolarDate
農曆年月日,必須包含西曆年。
LunisolarOutOfRangeError
超出農曆支援的日期範圍。
LunisolarYear
農曆西曆年,農曆新年所在的西曆年份。
SolarDate
西曆年月日。
SolarDayError
錯誤的西曆日。
SolarMonthError
錯誤的西曆月。
SolarOutOfRangeError
超出西曆支援的日期範圍。
SolarYear
西曆年份。
SolarYearError
錯誤的西曆年。

Enums§

ChineseVariant
The different writing systems used for the Chinese language. Traditional Chinese (繁體中文) or Simple Chinese (简体中文).
EarthlyBranch
列舉中國十二地支:子、丑、寅、卯、辰、巳、午、未、申、酉、戌、亥。
HeavenlyStems
列舉中國十天干:甲、乙、丙、丁、戊、己、更、辛、壬、葵。
LunarDay
列舉農曆三十個天數名稱:初一、初二、…、十一、十二、…、廿一、廿二、…、三十。
LunarMonth
列舉農曆十二個月份名稱:正月、二月、三月、四月、五月、六月、七月、八月、九月、十月、冬月、臘月。包含閏月。
LunisolarDateError
錯誤的農曆年月日。
SolarDateError
錯誤的西曆年月日。
SolarDay
列舉西曆三十一個天數名稱:一、二、…、十一、十二、…、二十一、二十二、…、三十、三十一。
SolarMonth
列舉西曆十二個月份名稱:一月、二月、三月、四月、五月、六月、七月、八月、九月、十月、十一月、十二月。
Zodiac
列舉中國十二生肖:鼠、牛、虎、兔、龍、蛇、馬、羊、猴、雞、狗、豬。

Constants§

MAX_LUNISOLAR_DATE_IN_SOLAR_DATE
最大支援的農曆日期(以西曆日期表示):2101-01-28。
MAX_YEAR_IN_SOLAR_CALENDAR
最大支援的農曆西曆年。
MIN_LUNISOLAR_DATE_IN_SOLAR_DATE
最小支援的農曆日期(以西曆日期表示):1901-02-19。
MIN_YEAR_IN_SOLAR_CALENDAR
最小支援的農曆西曆年。