Skip to main content

celestial_time/
lib.rs

1pub mod constants;
2pub mod julian;
3pub mod parsing;
4pub mod scales;
5pub mod sidereal;
6pub mod transforms;
7
8pub use julian::JulianDate;
9pub use scales::{GPS, TAI, TCB, TCG, TDB, TT, UT1, UTC};
10
11pub use scales::{
12    gps_from_calendar, tai_from_calendar, tcb_from_calendar, tcg_from_calendar, tdb_from_calendar,
13    tt_from_calendar, ut1_from_calendar, utc_from_calendar,
14};
15
16pub use scales::conversions::{
17    TcbToTdb, TdbToTcb, ToGPS, ToTAI, ToTAIWithOffset, ToTCB, ToTCG, ToTCGFromTCB, ToTDB, ToTT,
18    ToTTFromTDB, ToTTWithDeltaT, ToUT1, ToUT1WithDUT1, ToUT1WithDeltaT, ToUT1WithOffset, ToUTC,
19    ToUTCViaTAI, ToUTCWithDUT1,
20};
21pub use sidereal::{ObservatoryContext, SiderealAngle, GAST, GMST, LAST, LMST};
22pub use transforms::{NutationCalculator, NutationModel, NutationResult};
23
24#[cfg(feature = "serde")]
25use serde::{Deserialize, Serialize};
26
27pub type TimeResult<T> = Result<T, TimeError>;
28
29#[derive(Debug, Clone, PartialEq)]
30#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
31pub enum TimeError {
32    InvalidDate,
33    ConversionError(String),
34    ParseError(String),
35    CalculationError(String),
36    InvalidEpoch(String),
37}
38
39impl std::fmt::Display for TimeError {
40    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41        match self {
42            TimeError::InvalidDate => write!(f, "Invalid date"),
43            TimeError::ConversionError(msg) => write!(f, "Conversion error: {}", msg),
44            TimeError::ParseError(msg) => write!(f, "Parse error: {}", msg),
45            TimeError::CalculationError(msg) => write!(f, "Calculation error: {}", msg),
46            TimeError::InvalidEpoch(msg) => write!(f, "Invalid epoch: {}", msg),
47        }
48    }
49}
50
51impl std::error::Error for TimeError {}
52
53impl From<celestial_core::AstroError> for TimeError {
54    fn from(err: celestial_core::AstroError) -> Self {
55        TimeError::CalculationError(err.to_string())
56    }
57}