Skip to main content

lunar_lite/
error.rs

1use thiserror::Error;
2
3/// Errors from date conversion and validation.
4#[derive(Debug, Error, Clone, PartialEq, Eq)]
5pub enum LunarError {
6    /// The solar date is not a real calendar date.
7    #[error("Invalid solar date: {year:04}-{month:02}-{day:02}")]
8    InvalidSolarDate { year: i32, month: u8, day: u8 },
9    /// The lunar date does not exist in that lunar year.
10    #[error("Invalid lunar date: {year:04}-{month:02}-{day:02}, is_leap_month={is_leap_month}")]
11    InvalidLunarDate {
12        year: i32,
13        month: u8,
14        day: u8,
15        is_leap_month: bool,
16    },
17    /// The year falls outside the range covered by the generated tables.
18    #[error("Year {year} is out of supported range")]
19    YearOutOfRange { year: i32 },
20    /// The time is not a valid 24-hour wall-clock time.
21    #[error("Invalid time: {hour:02}:{minute:02}")]
22    InvalidTime { hour: u8, minute: u8 },
23    /// The time index is outside the valid `0..=12` range (时辰 index).
24    #[error("Invalid time index: {time_index} (expected 0..=12)")]
25    InvalidTimeIndex { time_index: u8 },
26    /// The Gregorian year falls outside the generated solar-term table range.
27    #[error("Year {year} is outside the supported solar-term range")]
28    SolarTermOutOfRange { year: i32 },
29}
30
31/// Errors from constructing a [`StemBranch`](crate::StemBranch).
32#[derive(Debug, Error, Clone, PartialEq, Eq)]
33pub enum StemBranchError {
34    /// The stem and branch do not share a position in the sexagenary cycle
35    /// (their indices have different parity).
36    #[error("Invalid stem-branch pair: {stem:?} - {branch:?}")]
37    InvalidStemBranchPair {
38        stem: crate::stem_branch::HeavenlyStem,
39        branch: crate::stem_branch::EarthlyBranch,
40    },
41}