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#[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 loop {
20 core::hint::spin_loop();
21 }
22}
23
24pub type Real = f64;
26
27#[macro_export]
28macro_rules! f {
29 ($x:expr) => {
30 $x as $crate::Real
31 };
32}
33
34macro_rules! safe_div_euc {
37 ($lhs:expr, $rhs:expr, $default:expr) => {{
38 match ($lhs).checked_div_euclid($rhs) {
39 Some(q) => q,
40 None => $default,
41 }
42 }};
43}
44
45macro_rules! safe_rem_euc {
48 ($lhs:expr, $rhs:expr, $default:expr) => {{
49 match ($lhs).checked_rem_euclid($rhs) {
50 Some(r) => r,
51 None => $default,
52 }
53 }};
54}
55
56#[inline(always)]
57pub const fn to_sec_f(attos: u128) -> Real {
58 f!(attos) / ATTOS_PER_SECF
59}
60
61#[inline(always)]
63pub fn to_sec(attos: i128) -> i128 {
64 attos / ATTOS_PER_SEC_I128
65}
66
67#[inline(always)]
69pub fn to_ms(attos: i128) -> i128 {
70 attos / ATTOS_PER_MS_I128
71}
72
73#[inline(always)]
75pub fn to_us(attos: i128) -> i128 {
76 attos / ATTOS_PER_US_I128
77}
78
79#[inline(always)]
81pub fn to_ns(attos: i128) -> i128 {
82 attos / ATTOS_PER_NS_I128
83}
84
85#[inline(always)]
87pub fn to_ps(attos: i128) -> i128 {
88 attos / ATTOS_PER_PS_I128
89}
90
91#[inline(always)]
93pub fn to_fs(attos: i128) -> i128 {
94 attos / ATTOS_PER_FS_I128
95}
96
97#[cfg(feature = "parse")]
101mod alloc_parse;
102
103#[cfg(feature = "sidereal")]
104pub mod sidereal;
105
106mod an_err;
110mod ascii_str;
111mod clock_model;
112mod drift;
113mod dt;
114mod gregorian_time;
115mod light_time;
116mod parser;
117mod position;
118mod scale;
119mod time_parts;
120mod time_range;
121
122pub mod constants;
126pub mod error;
127pub mod historical_sofa;
128pub mod leap_seconds;
129pub mod math;
130pub mod tzdb;
131
132#[cfg(feature = "bop")]
136pub mod bop;
137
138#[cfg(feature = "parse")]
142pub(crate) use alloc_parse::{
143 alloc_constants::*, date::*, date_classification::*, duration::*, lang_data::*, lang_map::*,
144 languages::en::*, parse_date::*, types::*,
145};
146
147pub(crate) use constants::*;
151
152#[cfg(feature = "parse")]
156pub use alloc_parse::types::{DateOrder, DateParseMode, Lang, ParseCfg};
157
158#[cfg(feature = "wire")]
159pub use an_err::{WireErr, WireLocation};
160
161#[cfg(feature = "sidereal")]
162pub use sidereal::Sidereal;
163
164pub use an_err::AnErr;
168pub use ascii_str::{AsciiStr, AsciiStrError};
169pub use clock_model::ClockModel;
170pub use drift::{Drift, Spacetime};
171pub use dt::Dt;
172pub use dt::numbers_traits::{AttosTraits, TimeTraits};
173pub use error::{DtErr, DtErrKind};
174pub use gregorian_time::{GregorianTime, YmdHms};
175pub use light_time::ObserverState;
176pub use math::{
177 atan::atan,
178 atan2::atan2,
179 cos::cos,
180 floor::floor_f,
181 log::log,
182 sin::sin,
183 sqrt::{hypot, sqrt},
184 tan::tan,
185};
186pub use position::{Position, Velocity};
187pub use scale::Scale;
188pub use time_parts::{Meridiem, Offset, TimeParts, Weekday};
189pub use time_range::{Every, TimeRange};