pub enum TimeDelta {
Valid {
seconds: i64,
attoseconds: i64,
},
NaN,
PosInf,
NegInf,
}Expand description
A signed time delta with attosecond precision.
TimeDelta represents a duration as whole seconds plus a fractional attosecond
component. It also supports sentinel values for NaN and positive/negative infinity.
Variants§
Valid
A finite time delta with whole seconds and an attosecond remainder in [0, 10¹⁸).
NaN
Not-a-number sentinel.
PosInf
Positive infinity sentinel.
NegInf
Negative infinity sentinel.
Implementations§
Source§impl TimeDelta
impl TimeDelta
Sourcepub const fn new(seconds: i64, attoseconds: i64) -> TimeDelta
pub const fn new(seconds: i64, attoseconds: i64) -> TimeDelta
Creates a new TimeDelta from seconds and attoseconds.
The attoseconds value is automatically normalized to [0, 10¹⁸), with overflow/underflow carried into the seconds component.
§Examples
use lox_core::time::deltas::TimeDelta;
let dt = TimeDelta::new(1, 500_000_000_000_000_000);
assert_eq!(dt.seconds(), Some(1));
assert_eq!(dt.attoseconds(), Some(500_000_000_000_000_000));Sourcepub const fn builder() -> TimeDeltaBuilder
pub const fn builder() -> TimeDeltaBuilder
Returns a TimeDeltaBuilder for constructing a TimeDelta from individual components.
Sourcepub const fn from_seconds_f64(value: f64) -> TimeDelta
pub const fn from_seconds_f64(value: f64) -> TimeDelta
Creates a TimeDelta from a floating-point number of seconds.
Returns NaN, PosInf, or NegInf for the corresponding special float values.
Sourcepub const fn from_seconds(seconds: i64) -> TimeDelta
pub const fn from_seconds(seconds: i64) -> TimeDelta
Creates a TimeDelta from a whole number of seconds.
Sourcepub const fn from_minutes(minutes: i64) -> TimeDelta
pub const fn from_minutes(minutes: i64) -> TimeDelta
Creates a TimeDelta from a whole number of minutes.
Sourcepub const fn from_minutes_f64(value: f64) -> TimeDelta
pub const fn from_minutes_f64(value: f64) -> TimeDelta
Creates a TimeDelta from a floating-point number of minutes.
Sourcepub const fn from_hours(hours: i64) -> TimeDelta
pub const fn from_hours(hours: i64) -> TimeDelta
Creates a TimeDelta from a whole number of hours.
Sourcepub const fn from_hours_f64(value: f64) -> TimeDelta
pub const fn from_hours_f64(value: f64) -> TimeDelta
Creates a TimeDelta from a floating-point number of hours.
Sourcepub const fn from_days(days: i64) -> TimeDelta
pub const fn from_days(days: i64) -> TimeDelta
Creates a TimeDelta from a whole number of days.
Sourcepub const fn from_days_f64(value: f64) -> TimeDelta
pub const fn from_days_f64(value: f64) -> TimeDelta
Creates a TimeDelta from a floating-point number of days.
Sourcepub const fn from_milliseconds(ms: i64) -> TimeDelta
pub const fn from_milliseconds(ms: i64) -> TimeDelta
Creates a TimeDelta from a number of milliseconds.
Sourcepub const fn from_microseconds(us: i64) -> TimeDelta
pub const fn from_microseconds(us: i64) -> TimeDelta
Creates a TimeDelta from a number of microseconds.
Sourcepub const fn from_nanoseconds(ns: i64) -> TimeDelta
pub const fn from_nanoseconds(ns: i64) -> TimeDelta
Creates a TimeDelta from a number of nanoseconds.
Sourcepub const fn from_picoseconds(ps: i64) -> TimeDelta
pub const fn from_picoseconds(ps: i64) -> TimeDelta
Creates a TimeDelta from a number of picoseconds.
Sourcepub const fn from_femtoseconds(fs: i64) -> TimeDelta
pub const fn from_femtoseconds(fs: i64) -> TimeDelta
Creates a TimeDelta from a number of femtoseconds.
Sourcepub const fn from_attoseconds(atto: i64) -> TimeDelta
pub const fn from_attoseconds(atto: i64) -> TimeDelta
Creates a TimeDelta from a number of attoseconds.
Sourcepub const fn from_julian_years(value: f64) -> TimeDelta
pub const fn from_julian_years(value: f64) -> TimeDelta
Creates a TimeDelta from a floating-point number of Julian years (365.25 days each).
Sourcepub const fn from_julian_centuries(value: f64) -> TimeDelta
pub const fn from_julian_centuries(value: f64) -> TimeDelta
Creates a TimeDelta from a floating-point number of Julian centuries (36525 days each).
Sourcepub const fn from_seconds_and_subsecond(
seconds: i64,
subsecond: Subsecond,
) -> TimeDelta
pub const fn from_seconds_and_subsecond( seconds: i64, subsecond: Subsecond, ) -> TimeDelta
Creates a TimeDelta from whole seconds and a Subsecond fractional part.
Sourcepub const fn from_seconds_and_subsecond_f64(
seconds: f64,
subsecond: f64,
) -> TimeDelta
pub const fn from_seconds_and_subsecond_f64( seconds: f64, subsecond: f64, ) -> TimeDelta
Creates a TimeDelta from floating-point seconds and a subsecond fraction.
Sourcepub const fn from_julian_date(julian_date: f64, epoch: Epoch) -> TimeDelta
pub const fn from_julian_date(julian_date: f64, epoch: Epoch) -> TimeDelta
Creates a TimeDelta from a Julian date relative to the given epoch.
Sourcepub const fn from_two_part_julian_date(jd1: f64, jd2: f64) -> TimeDelta
pub const fn from_two_part_julian_date(jd1: f64, jd2: f64) -> TimeDelta
Creates a TimeDelta from a two-part Julian date (jd1 + jd2).
Sourcepub const fn as_seconds_and_subsecond(&self) -> Option<(i64, Subsecond)>
pub const fn as_seconds_and_subsecond(&self) -> Option<(i64, Subsecond)>
Returns the whole seconds and Subsecond components, or None for non-finite values.
Sourcepub const fn to_seconds(&self) -> Seconds
pub const fn to_seconds(&self) -> Seconds
Sourcepub const fn is_negative(&self) -> bool
pub const fn is_negative(&self) -> bool
Returns true if the time delta is negative.
Sourcepub const fn is_positive(&self) -> bool
pub const fn is_positive(&self) -> bool
Returns true if the time delta is positive.
Sourcepub const fn is_finite(&self) -> bool
pub const fn is_finite(&self) -> bool
Returns true if the time delta is a finite value (not NaN or infinite).
Sourcepub const fn is_infinite(&self) -> bool
pub const fn is_infinite(&self) -> bool
Returns true if the time delta is positive or negative infinity.
Sourcepub const fn seconds(&self) -> Option<i64>
pub const fn seconds(&self) -> Option<i64>
Returns the whole seconds component, or None for non-finite values.
Sourcepub const fn subsecond(&self) -> Option<f64>
pub const fn subsecond(&self) -> Option<f64>
Returns the subsecond fraction as an f64, or None for non-finite values.
Sourcepub const fn attoseconds(&self) -> Option<i64>
pub const fn attoseconds(&self) -> Option<i64>
Returns the attosecond component, or None for non-finite values.
Sourcepub const fn add_const(self, rhs: TimeDelta) -> TimeDelta
pub const fn add_const(self, rhs: TimeDelta) -> TimeDelta
Adds two TimeDelta values in a const context.
Trait Implementations§
Source§impl AddAssign for TimeDelta
impl AddAssign for TimeDelta
Source§fn add_assign(&mut self, rhs: TimeDelta)
fn add_assign(&mut self, rhs: TimeDelta)
+= operation. Read moreSource§impl JulianDate for TimeDelta
impl JulianDate for TimeDelta
Source§fn two_part_julian_date(&self) -> (f64, f64)
fn two_part_julian_date(&self) -> (f64, f64)
Source§fn seconds_since_julian_epoch(&self) -> f64
fn seconds_since_julian_epoch(&self) -> f64
f64.Source§fn seconds_since_modified_julian_epoch(&self) -> f64
fn seconds_since_modified_julian_epoch(&self) -> f64
f64.Source§fn seconds_since_j1950(&self) -> f64
fn seconds_since_j1950(&self) -> f64
f64.Source§fn seconds_since_j2000(&self) -> f64
fn seconds_since_j2000(&self) -> f64
f64.Source§fn days_since_julian_epoch(&self) -> f64
fn days_since_julian_epoch(&self) -> f64
f64.Source§fn days_since_modified_julian_epoch(&self) -> f64
fn days_since_modified_julian_epoch(&self) -> f64
f64.Source§fn days_since_j1950(&self) -> f64
fn days_since_j1950(&self) -> f64
f64.Source§fn days_since_j2000(&self) -> f64
fn days_since_j2000(&self) -> f64
f64.Source§fn years_since_julian_epoch(&self) -> f64
fn years_since_julian_epoch(&self) -> f64
f64.Source§fn years_since_modified_julian_epoch(&self) -> f64
fn years_since_modified_julian_epoch(&self) -> f64
f64.Source§fn years_since_j1950(&self) -> f64
fn years_since_j1950(&self) -> f64
f64.Source§fn years_since_j2000(&self) -> f64
fn years_since_j2000(&self) -> f64
f64.Source§fn centuries_since_julian_epoch(&self) -> f64
fn centuries_since_julian_epoch(&self) -> f64
f64.Source§fn centuries_since_modified_julian_epoch(&self) -> f64
fn centuries_since_modified_julian_epoch(&self) -> f64
f64.Source§fn centuries_since_j1950(&self) -> f64
fn centuries_since_j1950(&self) -> f64
f64.Source§fn centuries_since_j2000(&self) -> f64
fn centuries_since_j2000(&self) -> f64
f64.Source§impl Ord for TimeDelta
impl Ord for TimeDelta
Source§impl PartialOrd for TimeDelta
impl PartialOrd for TimeDelta
Source§impl SubAssign for TimeDelta
impl SubAssign for TimeDelta
Source§fn sub_assign(&mut self, rhs: TimeDelta)
fn sub_assign(&mut self, rhs: TimeDelta)
-= operation. Read moreimpl Copy for TimeDelta
impl Eq for TimeDelta
impl StructuralPartialEq for TimeDelta
Auto Trait Implementations§
impl Freeze for TimeDelta
impl RefUnwindSafe for TimeDelta
impl Send for TimeDelta
impl Sync for TimeDelta
impl Unpin for TimeDelta
impl UnsafeUnpin for TimeDelta
impl UnwindSafe for TimeDelta
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more