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 = "ut1")]
81mod ut1;
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 CRATE USE
111// _________________________________________
112#[cfg(feature = "parse")]
113pub(crate) use alloc_parse::{
114    alloc_constants::*, date::*, date_classification::*, duration::*, lang_data::*, lang_map::*,
115    languages::en::*, parse_date::*, types::*,
116};
117
118// _________________________________________
119// CRATE USE
120// _________________________________________
121pub(crate) use constants::*;
122pub(crate) use utils::*;
123
124// _________________________________________
125// FEATURE PUB USE
126// _________________________________________
127#[cfg(feature = "parse")]
128pub use alloc_parse::types::{DateOrder, DateParseMode, Lang, ParseCfg};
129
130#[cfg(feature = "ut1")]
131pub use ut1::{Separator, Ut1Columns, Ut1Data, Ut1Format, Ut1Row};
132
133#[cfg(feature = "wire")]
134pub use an_err::{WireErr, WireLocation};
135
136// _________________________________________
137// PUB USE
138// _________________________________________
139pub use an_err::AnErr;
140pub use ascii_str::{AsciiStr, AsciiStrError};
141pub use clock_model::ClockModel;
142pub use drift::{Drift, Spacetime};
143pub use dt::Dt;
144pub use dt::time_units::{AttosUnits, TimeUnits};
145pub use error::{DtErr, DtErrKind};
146pub use gregorian_time::{GregorianTime, YmdHms};
147pub use light_time::{LightContext, ObserverState};
148pub use position::{Position, Velocity};
149pub use scale::Scale;
150pub use time_parts::{Meridiem, Offset, TimeParts, Weekday};
151pub use time_range::{Every, TimeRange};