Skip to main content

lunar_lite/
lib.rs

1//! `lunar-lite` is a small library for Chinese lunisolar date conversion.
2//!
3//! It converts between the Gregorian (solar) calendar and the Chinese lunar
4//! calendar, and exposes the sexagenary cycle (六十甲子) of Heavenly Stems and
5//! Earthly Branches.
6//!
7//! # Examples
8//!
9//! ```
10//! use lunar_lite::{solar_to_lunar, lunar_to_solar, SolarDate, LunarDate};
11//!
12//! let solar = SolarDate { year: 2024, month: 2, day: 10 };
13//! let lunar = solar_to_lunar(solar).unwrap();
14//! assert_eq!(lunar, LunarDate { year: 2024, month: 1, day: 1, is_leap_month: false });
15//!
16//! // Round-trips back to the original solar date.
17//! assert_eq!(lunar_to_solar(lunar).unwrap(), solar);
18//! ```
19//!
20//! # Supported range
21//!
22//! Conversions are backed by a generated table of per-year data; years outside
23//! the supported range return [`LunarError::YearOutOfRange`].
24//!
25//! # Features
26//!
27//! - `serde`: derive `Serialize`/`Deserialize` for the public date and
28//!   stem-branch types.
29
30mod calendar;
31mod convert;
32mod date;
33mod error;
34mod four_pillars;
35mod generated;
36mod julian_day;
37mod normalize;
38mod sexagenary;
39mod solar_terms;
40mod stem_branch;
41mod time_index;
42mod year_info;
43
44pub use convert::{lunar_to_solar, solar_to_lunar};
45pub use date::{LunarDate, SolarDate};
46pub use error::{LunarError, StemBranchError};
47pub use four_pillars::{
48    FourPillars, HeavenlyStemAndEarthlyBranchDate, MonthDivide, StemBranchOptions, YearDivide,
49    four_pillars_from_solar_date, four_pillars_from_solar_date_with_options,
50    get_heavenly_stem_and_earthly_branch_by_solar_date,
51    get_heavenly_stem_and_earthly_branch_by_solar_date_with_options,
52};
53pub use normalize::normalize_lunar_date;
54pub use sexagenary::{StemBranch, lunar_year_branch, lunar_year_stem, lunar_year_stem_branch};
55pub use stem_branch::{EARTHLY_BRANCHES, EarthlyBranch, HEAVENLY_STEMS, HeavenlyStem};
56pub use time_index::{is_early_zi, is_late_zi, time_index, time_index_to_branch};