Skip to main content

deep_time/
lib.rs

1#![cfg_attr(test, allow(clippy::all))]
2#![cfg_attr(not(feature = "std"), no_std)]
3
4#[cfg(feature = "alloc")]
5extern crate alloc;
6#[cfg(feature = "std")]
7extern crate std;
8
9// ──────────────────────────────────────────────────────────────
10// Optional panic handler (opt-in via feature)
11// ──────────────────────────────────────────────────────────────
12#[cfg(all(feature = "panic-handler", not(feature = "std"), not(test)))]
13use core::panic::PanicInfo;
14
15#[cfg(all(feature = "panic-handler", not(feature = "std"), not(test)))]
16#[panic_handler]
17fn panic(_info: &PanicInfo) -> ! {
18    // Uses spin_loop() for better power characteristics than plain loop{}
19    loop {
20        core::hint::spin_loop();
21    }
22}
23
24/// Alias for f64, maybe upgrade one day
25pub type Real = f64;
26
27/// Convert a number to the crates [`Real`] type (f64).
28///
29/// Equivalent to `n as f64`.
30#[macro_export]
31macro_rules! f {
32    ($x:expr) => {
33        $x as $crate::Real
34    };
35}
36
37/// Safe Euclidean division.
38/// Returns `default` if `rhs == 0` or if `lhs == i128::MIN && rhs == -1`.
39macro_rules! safe_div_euc {
40    ($lhs:expr, $rhs:expr, $default:expr) => {{
41        match ($lhs).checked_div_euclid($rhs) {
42            Some(q) => q,
43            None => $default,
44        }
45    }};
46}
47
48/// Safe Euclidean remainder.
49/// Returns `$default` if `rhs == 0` or if `lhs == Self::MIN && rhs == -1`.
50macro_rules! safe_rem_euc {
51    ($lhs:expr, $rhs:expr, $default:expr) => {{
52        match ($lhs).checked_rem_euclid($rhs) {
53            Some(r) => r,
54            None => $default,
55        }
56    }};
57}
58
59/// Turns a list of string literals into an array of `&'static [u8]`.
60macro_rules! byte_arrays {
61    ( $( $s:literal ),+ $(,)? ) => {
62        [ $( $s.as_bytes() ),+ ]
63    };
64}
65
66// _________________________________________
67// FEATURE MOD
68// _________________________________________
69#[cfg(feature = "parse")]
70mod alloc_parse;
71#[cfg(feature = "physics")]
72mod physics;
73
74// _________________________________________
75// MOD
76// _________________________________________
77mod dt;
78mod lite_str;
79mod locale;
80mod scale;
81mod strtime;
82mod time_range;
83mod ymdhms;
84
85// _________________________________________
86// PUB MOD
87// _________________________________________
88pub mod an_err;
89pub mod civil_parts;
90pub mod constants;
91pub mod error;
92pub mod historical_utc;
93pub mod leap_seconds;
94pub mod math;
95pub mod tz;
96
97// _________________________________________
98// FEATURE PUB MOD
99// _________________________________________
100#[cfg(feature = "eop")]
101pub mod eop;
102
103#[cfg(feature = "sidereal")]
104pub mod sidereal;
105
106// _________________________________________
107// FEATURE CRATE USE
108// _________________________________________
109#[cfg(feature = "parse")]
110pub(crate) use alloc_parse::{
111    alloc_constants::*, date::*, date_classification::*, duration::*, helpers::*, parse_date::*,
112    types::*,
113};
114#[cfg(feature = "parse")]
115pub(crate) use locale::{lang_data::*, lang_map::*};
116
117// _________________________________________
118// CRATE USE
119// _________________________________________
120pub(crate) use civil_parts::*;
121pub(crate) use constants::*;
122pub(crate) use locale::*;
123#[allow(unused_imports)]
124pub(crate) use math::{
125    atan2::atan2,
126    cos::cos,
127    div::rem_euclid_f,
128    floor::floor_f,
129    log::log,
130    sin::sin,
131    sqrt::{hypot, sqrt},
132};
133pub(crate) use strtime::*;
134
135// _________________________________________
136// FEATURE PUB USE
137// _________________________________________
138#[cfg(feature = "parse")]
139pub use alloc_parse::types::{Mode, Order, ParseCfg};
140
141#[cfg(feature = "mars")]
142pub use dt::mars;
143
144#[cfg(feature = "sidereal")]
145pub use sidereal::Sidereal;
146
147#[cfg(feature = "physics")]
148pub use physics::{
149    drift::Drift, observer::Observer, position::Position, spacetime::Spacetime, velocity::Velocity,
150};
151
152// _________________________________________
153// PUB USE
154// _________________________________________
155pub use an_err::AnErr;
156pub use dt::Dt;
157pub use dt::lunar;
158pub use dt::numbers_traits::{AttosTraits, TimeTraits};
159pub use error::{DtErr, DtErrKind};
160pub use lite_str::LiteStr;
161pub use locale::Lang;
162pub use scale::Scale;
163pub use strtime::StrPTimeFmt;
164pub use time_range::{Every, TimeRange};
165pub use ymdhms::YmdHms;