Expand description

Chinese Lunisolar Calendar

The traditional Chinese Calendar, called 農曆 or 陰曆 in Chinese, is based on the moon, so it’s also known as Lunar Calendar.

Because the cycle of Lunar Calendar is 60 years and there are no regular rules for the days in each lunar month and even the number of months in a lunar year, it’s hard to use Lunar Calendar without referencing any other calendars. The Lunisolar Calendar is a way to combine both of the Solar Calendar (Gregorian Calendar) and the Lunar Calendar in order to make it accurate, predictable and useful.

The Lunisolar Calendar relies on three datasets, BIG_MONTHS, LEAP_MONTHS, and NEW_YEAR_DIFFERENCE which are written in the constants.rs file. Currently, the data range is from 1901 to 2100 (lunisolar year), so this Lunisolar Calendar supports from 1901-02-19 to 2101-01-28 (in Solar Calendar).

This library allows you to convert a date between the Lunisolar Calendar and the Solar Calendar, and to compute the weight of Ba Zi(八字). Moreover, it can convert a date to a Chinese text string and parse a Chinese text string to a date in Simple Chinese or Traditional Chinese.

Examples

extern crate chinese_lunisolar_calendar;

use chinese_lunisolar_calendar::chrono::prelude::*;

use chinese_lunisolar_calendar::SolarDate;

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

assert_eq!("二零一九年一月十五日", solar_date.to_chinese_string());
extern crate chinese_lunisolar_calendar;

use chinese_lunisolar_calendar::chrono::prelude::*;

use chinese_lunisolar_calendar::{ChineseVariant, LunisolarDate};

let lunisolar_date = LunisolarDate::from_naive_date(NaiveDate::from_ymd(2019, 1, 15)).unwrap();

assert_eq!(2019, lunisolar_date.get_solar_year().to_u16());
assert_eq!("二零一八 戊戌、狗年 臘月 初十", lunisolar_date.to_chinese_string(ChineseVariant::Traditional));
assert_eq!("二零一八 戊戌、狗年 腊月 初十", lunisolar_date.to_chinese_string(ChineseVariant::Simple));

assert_eq!(4.3, lunisolar_date.get_ba_zi_weight_by_time(NaiveTime::from_hms(15, 30, 0)));

Re-exports

pub extern crate chrono;

Structs

農曆年份,由天干加地支組成,六十年一輪。
農曆年月日,必須包含西曆年。
農曆西曆年,農曆新年所在的西曆年份。
最大支援的農曆日期(以西曆日期表示):2101-01-28。(lazy_static的實體)
最小支援的農曆日期(以西曆日期表示):1901-02-19。(lazy_static的實體)
西曆年月日。
西曆年份。

Enums

繁體中文(Traditional Chinese)或簡體中文(Simple Chinese)。
列舉中國十二地支:子、丑、寅、卯、辰、巳、午、未、申、酉、戌、亥。
列舉中國十天干:甲、乙、丙、丁、戊、己、更、辛、壬、葵。
列舉農曆三十個天數名稱:初一、初二、…、十一、十二、…、廿一、廿二、…、三十。
列舉農曆十二個月份名稱:正月、二月、三月、四月、五月、六月、七月、八月、九月、十月、冬月、臘月。包含閏月。
列舉西曆三十一個天數名稱:一、二、…、十一、十二、…、二十一、二十二、…、三十、三十一。
列舉西曆十二個月份名稱:一月、二月、三月、四月、五月、六月、七月、八月、九月、十月、十一月、十二月。
列舉中國十二生肖:鼠、牛、虎、兔、龍、蛇、馬、羊、猴、雞、狗、豬。

Constants

最大支援的農曆西曆年。(u16)
最小支援的農曆西曆年。(u16)