Skip to main content

deep_time/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2
3#[cfg(feature = "alloc")]
4extern crate alloc;
5#[cfg(feature = "std")]
6extern crate std;
7
8// ──────────────────────────────────────────────────────────────
9// Optional panic handler (opt-in via feature)
10// ──────────────────────────────────────────────────────────────
11#[cfg(all(feature = "panic-handler", not(feature = "std"), not(test)))]
12use core::panic::PanicInfo;
13
14#[cfg(all(feature = "panic-handler", not(feature = "std"), not(test)))]
15#[panic_handler]
16fn panic(_info: &PanicInfo) -> ! {
17    // Uses spin_loop() for better power characteristics than plain loop{}
18    loop {
19        core::hint::spin_loop();
20    }
21}
22
23// possibly upgrade to f128 when it's stable
24pub type Real = f64;
25
26#[macro_export]
27macro_rules! f {
28    ($x:expr) => {
29        $x as $crate::Real
30    };
31}
32
33#[inline(always)]
34pub const fn to_sec_f(attos: u128) -> Real {
35    f!(attos) / ATTOS_PER_SECF
36}
37
38/// Converts attoseconds → seconds (s)
39#[inline(always)]
40pub fn to_sec(attos: i128) -> i128 {
41    attos / ATTOS_PER_SEC_I128
42}
43
44/// Converts attoseconds → milliseconds (ms)
45#[inline(always)]
46pub fn to_ms(attos: i128) -> i128 {
47    attos / ATTOS_PER_MS_I128
48}
49
50/// Converts attoseconds → microseconds (us)
51#[inline(always)]
52pub fn to_us(attos: i128) -> i128 {
53    attos / ATTOS_PER_US_I128
54}
55
56/// Converts attoseconds → nanoseconds (ns)
57#[inline(always)]
58pub fn to_ns(attos: i128) -> i128 {
59    attos / ATTOS_PER_NS_I128
60}
61
62/// Converts attoseconds → picoseconds (ps)
63#[inline(always)]
64pub fn to_ps(attos: i128) -> i128 {
65    attos / ATTOS_PER_PS_I128
66}
67
68/// Converts attoseconds → femtoseconds (fs)
69#[inline(always)]
70pub fn to_fs(attos: i128) -> i128 {
71    attos / ATTOS_PER_FS_I128
72}
73
74// _________________________________________
75// FEATURE MOD
76// _________________________________________
77#[cfg(feature = "parse")]
78mod alloc_parse;
79
80#[cfg(feature = "sidereal")]
81mod sidereal;
82
83// _________________________________________
84// MOD
85// _________________________________________
86mod an_err;
87mod ascii_str;
88mod clock_model;
89mod drift;
90mod dt;
91mod gregorian_time;
92mod light_time;
93mod parser;
94mod position;
95mod scale;
96mod time_parts;
97mod time_range;
98
99// _________________________________________
100// PUB MOD
101// _________________________________________
102pub mod constants;
103pub mod error;
104pub mod historical_sofa;
105pub mod leap_seconds;
106pub mod tzdb;
107pub mod utils;
108
109// _________________________________________
110// FEATURE PUB MOD
111// _________________________________________
112#[cfg(feature = "bop")]
113pub mod bop;
114
115// _________________________________________
116// FEATURE CRATE USE
117// _________________________________________
118#[cfg(feature = "parse")]
119pub(crate) use alloc_parse::{
120    alloc_constants::*, date::*, date_classification::*, duration::*, lang_data::*, lang_map::*,
121    languages::en::*, parse_date::*, types::*,
122};
123
124// _________________________________________
125// CRATE USE
126// _________________________________________
127pub(crate) use constants::*;
128pub(crate) use utils::*;
129
130// _________________________________________
131// FEATURE PUB USE
132// _________________________________________
133#[cfg(feature = "parse")]
134pub use alloc_parse::types::{DateOrder, DateParseMode, Lang, ParseCfg};
135
136#[cfg(feature = "wire")]
137pub use an_err::{WireErr, WireLocation};
138
139#[cfg(feature = "sidereal")]
140pub use sidereal::Sidereal;
141
142// _________________________________________
143// PUB USE
144// _________________________________________
145pub use an_err::AnErr;
146pub use ascii_str::{AsciiStr, AsciiStrError};
147pub use clock_model::ClockModel;
148pub use drift::{Drift, Spacetime};
149pub use dt::Dt;
150pub use dt::numbers_traits::{AttosTraits, TimeTraits};
151pub use error::{DtErr, DtErrKind};
152pub use gregorian_time::{GregorianTime, YmdHms};
153pub use light_time::ObserverState;
154pub use position::{Position, Velocity};
155pub use scale::Scale;
156pub use time_parts::{Meridiem, Offset, TimeParts, Weekday};
157pub use time_range::{Every, TimeRange};