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;
25macro_rules! f {
26    ($x:expr) => {
27        $x as Real
28    };
29}
30
31#[inline(always)]
32pub const fn to_sec_f(attos: u128) -> Real {
33    f!(attos) / ATTOS_PER_SECF
34}
35
36/// Converts attoseconds → seconds (s)
37#[inline(always)]
38pub fn to_sec(attos: i128) -> i128 {
39    attos / ATTOS_PER_SEC_I128
40}
41
42/// Converts attoseconds → milliseconds (ms)
43#[inline(always)]
44pub fn to_ms(attos: i128) -> i128 {
45    attos / ATTOS_PER_MS_I128
46}
47
48/// Converts attoseconds → microseconds (us)
49#[inline(always)]
50pub fn to_us(attos: i128) -> i128 {
51    attos / ATTOS_PER_US_I128
52}
53
54/// Converts attoseconds → nanoseconds (ns)
55#[inline(always)]
56pub fn to_ns(attos: i128) -> i128 {
57    attos / ATTOS_PER_NS_I128
58}
59
60/// Converts attoseconds → picoseconds (ps)
61#[inline(always)]
62pub fn to_ps(attos: i128) -> i128 {
63    attos / ATTOS_PER_PS_I128
64}
65
66/// Converts attoseconds → femtoseconds (fs)
67#[inline(always)]
68pub fn to_fs(attos: i128) -> i128 {
69    attos / ATTOS_PER_FS_I128
70}
71
72// _________________________________________
73// FEATURE MOD
74// _________________________________________
75#[cfg(feature = "parse")]
76mod alloc_parse;
77
78#[cfg(feature = "ut1")]
79mod ut1;
80
81// _________________________________________
82// MOD
83// _________________________________________
84mod an_err;
85mod ascii_str;
86mod clock_drift;
87mod clock_model;
88mod dt;
89mod gregorian_time;
90mod light_time;
91mod parser;
92mod position;
93mod scale;
94mod t_span;
95mod time_parts;
96mod time_range;
97
98// _________________________________________
99// PUB MOD
100// _________________________________________
101pub mod constants;
102pub mod error;
103pub mod historical_sofa;
104pub mod leap_seconds;
105pub mod tzdb;
106pub mod utils;
107
108// _________________________________________
109// FEATURE CRATE USE
110// _________________________________________
111#[cfg(feature = "parse")]
112pub(crate) use alloc_parse::{
113    alloc_constants::*, date::*, date_classification::*, duration::*, lang_data::*, lang_map::*,
114    languages::en::*, parse_date::*, types::*,
115};
116
117// _________________________________________
118// CRATE USE
119// _________________________________________
120pub(crate) use constants::*;
121pub(crate) use utils::*;
122
123// _________________________________________
124// FEATURE PUB USE
125// _________________________________________
126#[cfg(feature = "parse")]
127pub use alloc_parse::types::{DateOrder, DateParseMode, Lang, ParseCfg};
128
129#[cfg(feature = "ut1")]
130pub use ut1::{Separator, Ut1Columns, Ut1Data, Ut1Format, Ut1Row};
131
132#[cfg(feature = "wire")]
133pub use an_err::{WireErr, WireLocation};
134
135// _________________________________________
136// PUB USE
137// _________________________________________
138pub use an_err::AnErr;
139pub use ascii_str::{AsciiStr, AsciiStrError};
140pub use clock_drift::{ClockDrift, LocalSpacetime};
141pub use clock_model::ClockModel;
142pub use dt::Dt;
143pub use error::{DtErr, DtErrKind};
144pub use gregorian_time::GregorianTime;
145pub use light_time::{LightContext, ObserverState};
146pub use position::{Position, Velocity};
147pub use scale::Scale;
148pub use t_span::TSpan;
149pub use t_span::time_units::{AttosUnits, TimeUnits};
150pub use time_parts::{Meridiem, Offset, TimeParts, Weekday};
151pub use time_range::{Every, TimeRange};