1#![cfg_attr(test, allow(clippy::unwrap_used))]
2#![cfg_attr(test, allow(clippy::expect_used))]
3#![cfg_attr(not(feature = "std"), no_std)]
4
5#[cfg(feature = "alloc")]
6extern crate alloc;
7#[cfg(feature = "std")]
8extern crate std;
9
10#[cfg(all(feature = "panic-handler", not(feature = "std"), not(test)))]
14use core::panic::PanicInfo;
15
16#[cfg(all(feature = "panic-handler", not(feature = "std"), not(test)))]
17#[panic_handler]
18fn panic(_info: &PanicInfo) -> ! {
19 loop {
21 core::hint::spin_loop();
22 }
23}
24
25pub type Real = f64;
27
28#[macro_export]
29macro_rules! f {
30 ($x:expr) => {
31 $x as $crate::Real
32 };
33}
34
35macro_rules! safe_div_euc {
38 ($lhs:expr, $rhs:expr, $default:expr) => {{
39 match ($lhs).checked_div_euclid($rhs) {
40 Some(q) => q,
41 None => $default,
42 }
43 }};
44}
45
46macro_rules! safe_rem_euc {
49 ($lhs:expr, $rhs:expr, $default:expr) => {{
50 match ($lhs).checked_rem_euclid($rhs) {
51 Some(r) => r,
52 None => $default,
53 }
54 }};
55}
56
57#[inline(always)]
58pub const fn to_sec_f(attos: u128) -> Real {
59 f!(attos) / ATTOS_PER_SECF
60}
61
62#[inline(always)]
64pub fn to_sec(attos: i128) -> i128 {
65 attos / ATTOS_PER_SEC_I128
66}
67
68#[inline(always)]
70pub fn to_ms(attos: i128) -> i128 {
71 attos / ATTOS_PER_MS_I128
72}
73
74#[inline(always)]
76pub fn to_us(attos: i128) -> i128 {
77 attos / ATTOS_PER_US_I128
78}
79
80#[inline(always)]
82pub fn to_ns(attos: i128) -> i128 {
83 attos / ATTOS_PER_NS_I128
84}
85
86#[inline(always)]
88pub fn to_ps(attos: i128) -> i128 {
89 attos / ATTOS_PER_PS_I128
90}
91
92#[inline(always)]
94pub fn to_fs(attos: i128) -> i128 {
95 attos / ATTOS_PER_FS_I128
96}
97
98#[cfg(feature = "parse")]
102mod alloc_parse;
103
104#[cfg(feature = "sidereal")]
105pub mod sidereal;
106
107mod an_err;
111mod ascii_str;
112mod clock_model;
113mod drift;
114mod dt;
115mod gregorian_time;
116mod light_time;
117mod parser;
118mod position;
119mod scale;
120mod time_parts;
121mod time_range;
122
123pub mod constants;
127pub mod error;
128pub mod historical_sofa;
129pub mod leap_seconds;
130pub mod math;
131pub mod tzdb;
132
133#[cfg(feature = "bop")]
137pub mod bop;
138
139#[cfg(feature = "parse")]
143pub(crate) use alloc_parse::{
144 alloc_constants::*, date::*, date_classification::*, duration::*, lang_data::*, lang_map::*,
145 languages::en::*, parse_date::*, types::*,
146};
147
148pub(crate) use constants::*;
152
153#[cfg(feature = "parse")]
157pub use alloc_parse::types::{DateOrder, DateParseMode, Lang, ParseCfg};
158
159#[cfg(feature = "wire")]
160pub use an_err::{WireErr, WireLocation};
161
162#[cfg(feature = "sidereal")]
163pub use sidereal::Sidereal;
164
165pub use an_err::AnErr;
169pub use ascii_str::{AsciiStr, AsciiStrError};
170pub use clock_model::ClockModel;
171pub use drift::{Drift, Spacetime};
172pub use dt::Dt;
173pub use dt::numbers_traits::{AttosTraits, TimeTraits};
174pub use error::{DtErr, DtErrKind};
175pub use gregorian_time::{GregorianTime, YmdHms};
176pub use light_time::ObserverState;
177pub use math::{
178 atan::atan,
179 atan2::atan2,
180 cos::cos,
181 floor::floor_f,
182 log::log,
183 sin::sin,
184 sqrt::{hypot, sqrt},
185 tan::tan,
186};
187pub use position::{Position, Velocity};
188pub use scale::Scale;
189pub use time_parts::{Meridiem, Offset, TimeParts, Weekday};
190pub use time_range::{Every, TimeRange};