Skip to main content

Crate lunar_lite

Crate lunar_lite 

Source
Expand description

lunar-lite is a small library for Chinese lunisolar date conversion.

It converts between the Gregorian (solar) calendar and the Chinese lunar calendar, and exposes the sexagenary cycle (六十甲子) of Heavenly Stems and Earthly Branches.

§Examples

use lunar_lite::{solar_to_lunar, lunar_to_solar, SolarDate, LunarDate};

let solar = SolarDate { year: 2024, month: 2, day: 10 };
let lunar = solar_to_lunar(solar).unwrap();
assert_eq!(lunar, LunarDate { year: 2024, month: 1, day: 1, is_leap_month: false });

// Round-trips back to the original solar date.
assert_eq!(lunar_to_solar(lunar).unwrap(), solar);

§Supported range

Conversions are backed by a generated table of per-year data; years outside the supported range return LunarError::YearOutOfRange.

§Features

  • serde: derive Serialize/Deserialize for the public date and stem-branch types.

Structs§

FourPillars
The four pillars (年柱, 月柱, 日柱, 时柱) of a date and time.
LunarDate
A date in the Chinese lunar calendar.
SolarDate
A date in the Gregorian (solar) calendar.
StemBranch
A valid Heavenly Stem / Earthly Branch pair in the sexagenary cycle.
StemBranchOptions
Options controlling the year and month pillar boundaries.

Enums§

EarthlyBranch
One of the twelve Earthly Branches.
HeavenlyStem
One of the ten Heavenly Stems.
LunarError
Errors from date conversion and validation.
MonthDivide
How to resolve the month pillar across the month boundary.
StemBranchError
Errors from constructing a StemBranch.
YearDivide
How to resolve the year pillar across the year boundary.

Constants§

EARTHLY_BRANCHES
Canonical cyclic ordering of the twelve Earthly Branches.
HEAVENLY_STEMS
Canonical cyclic ordering of the ten Heavenly Stems.

Functions§

four_pillars_from_solar_date
Rust-native alias for get_heavenly_stem_and_earthly_branch_by_solar_date (default Exact/Exact options).
four_pillars_from_solar_date_with_options
Rust-native alias for get_heavenly_stem_and_earthly_branch_by_solar_date_with_options.
get_heavenly_stem_and_earthly_branch_by_solar_date
Computes the four pillars for a Gregorian solar date and 时辰 index, using the default (StemBranchOptions::default, i.e. Exact/Exact, matching lunar-lite@0.2.8).
get_heavenly_stem_and_earthly_branch_by_solar_date_with_options
Computes the four pillars for a Gregorian solar date and 时辰 index with explicit StemBranchOptions.
is_early_zi
Returns true if time_index is the early 子时 (0, 00:00–00:59).
is_late_zi
Returns true if time_index is the late 子时 (12, 23:00–23:59).
lunar_to_solar
Converts a Chinese lunar date to its Gregorian (solar) date.
lunar_year_branch
Returns the Earthly Branch of a Chinese lunar year (生年支).
lunar_year_stem
Returns the Heavenly Stem of a Chinese lunar year (生年干).
lunar_year_stem_branch
Returns the stem-branch of a Chinese lunar year.
normalize_lunar_date
Normalizes a lunar date and verifies that it actually exists.
solar_to_lunar
Converts a Gregorian (solar) date to its Chinese lunar date.
time_index
Returns the double-hour (時辰) index for a wall-clock time.
time_index_to_branch
Returns the Earthly Branch (时支) for a 时辰 index.

Type Aliases§

HeavenlyStemAndEarthlyBranchDate
Compatibility alias mirroring the TypeScript lunar-lite result name.