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§
- Lunar
DayError - 錯誤的農曆日。
- Lunar
Month Error - 錯誤的農曆月。
- Lunar
Year - 農曆年份,由天干加地支組成,六十年一輪。
- Lunar
Year Error - 錯誤的農曆年。
- Lunisolar
Date - 農曆年月日,必須包含西曆年。
- Lunisolar
OutOf Range Error - 超出農曆支援的日期範圍。
- Lunisolar
Year - 農曆西曆年,農曆新年所在的西曆年份。
- Solar
Date - 西曆年月日。
- Solar
DayError - 錯誤的西曆日。
- Solar
Month Error - 錯誤的西曆月。
- Solar
OutOf Range Error - 超出西曆支援的日期範圍。
- Solar
Year - 西曆年份。
- Solar
Year Error - 錯誤的西曆年。
Enums§
- Chinese
Variant - The different writing systems used for the Chinese language. Traditional Chinese (繁體中文) or Simple Chinese (简体中文).
- Earthly
Branch - 列舉中國十二地支:子、丑、寅、卯、辰、巳、午、未、申、酉、戌、亥。
- Heavenly
Stems - 列舉中國十天干:甲、乙、丙、丁、戊、己、更、辛、壬、葵。
- Lunar
Day - 列舉農曆三十個天數名稱:初一、初二、…、十一、十二、…、廿一、廿二、…、三十。
- Lunar
Month - 列舉農曆十二個月份名稱:正月、二月、三月、四月、五月、六月、七月、八月、九月、十月、冬月、臘月。包含閏月。
- Lunisolar
Date Error - 錯誤的農曆年月日。
- Solar
Date Error - 錯誤的西曆年月日。
- Solar
Day - 列舉西曆三十一個天數名稱:一、二、…、十一、十二、…、二十一、二十二、…、三十、三十一。
- Solar
Month - 列舉西曆十二個月份名稱:一月、二月、三月、四月、五月、六月、七月、八月、九月、十月、十一月、十二月。
- 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 - 最小支援的農曆西曆年。