Skip to main content

TimeDelta

Enum TimeDelta 

Source
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¹⁸).

Fields

§seconds: i64

Whole seconds component.

§attoseconds: i64

Attosecond remainder in [0, 10¹⁸).

§

NaN

Not-a-number sentinel.

§

PosInf

Positive infinity sentinel.

§

NegInf

Negative infinity sentinel.

Implementations§

Source§

impl TimeDelta

Source

pub const ZERO: TimeDelta

A zero-length time delta.

Source

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));
Source

pub const fn builder() -> TimeDeltaBuilder

Returns a TimeDeltaBuilder for constructing a TimeDelta from individual components.

Source

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.

Source

pub const fn from_seconds(seconds: i64) -> TimeDelta

Creates a TimeDelta from a whole number of seconds.

Source

pub const fn from_minutes(minutes: i64) -> TimeDelta

Creates a TimeDelta from a whole number of minutes.

Source

pub const fn from_minutes_f64(value: f64) -> TimeDelta

Creates a TimeDelta from a floating-point number of minutes.

Source

pub const fn from_hours(hours: i64) -> TimeDelta

Creates a TimeDelta from a whole number of hours.

Source

pub const fn from_hours_f64(value: f64) -> TimeDelta

Creates a TimeDelta from a floating-point number of hours.

Source

pub const fn from_days(days: i64) -> TimeDelta

Creates a TimeDelta from a whole number of days.

Source

pub const fn from_days_f64(value: f64) -> TimeDelta

Creates a TimeDelta from a floating-point number of days.

Source

pub const fn from_milliseconds(ms: i64) -> TimeDelta

Creates a TimeDelta from a number of milliseconds.

Source

pub const fn from_microseconds(us: i64) -> TimeDelta

Creates a TimeDelta from a number of microseconds.

Source

pub const fn from_nanoseconds(ns: i64) -> TimeDelta

Creates a TimeDelta from a number of nanoseconds.

Source

pub const fn from_picoseconds(ps: i64) -> TimeDelta

Creates a TimeDelta from a number of picoseconds.

Source

pub const fn from_femtoseconds(fs: i64) -> TimeDelta

Creates a TimeDelta from a number of femtoseconds.

Source

pub const fn from_attoseconds(atto: i64) -> TimeDelta

Creates a TimeDelta from a number of attoseconds.

Source

pub const fn from_julian_years(value: f64) -> TimeDelta

Creates a TimeDelta from a floating-point number of Julian years (365.25 days each).

Source

pub const fn from_julian_centuries(value: f64) -> TimeDelta

Creates a TimeDelta from a floating-point number of Julian centuries (36525 days each).

Source

pub const fn from_seconds_and_subsecond( seconds: i64, subsecond: Subsecond, ) -> TimeDelta

Creates a TimeDelta from whole seconds and a Subsecond fractional part.

Source

pub const fn from_seconds_and_subsecond_f64( seconds: f64, subsecond: f64, ) -> TimeDelta

Creates a TimeDelta from floating-point seconds and a subsecond fraction.

Source

pub const fn from_julian_date(julian_date: f64, epoch: Epoch) -> TimeDelta

Creates a TimeDelta from a Julian date relative to the given epoch.

Source

pub const fn from_two_part_julian_date(jd1: f64, jd2: f64) -> TimeDelta

Creates a TimeDelta from a two-part Julian date (jd1 + jd2).

Source

pub const fn as_seconds_and_subsecond(&self) -> Option<(i64, Subsecond)>

Returns the whole seconds and Subsecond components, or None for non-finite values.

Source

pub const fn to_seconds(&self) -> Seconds

Returns the time delta as a high-precision Seconds representation.

The result is a Seconds where hi contains the whole seconds and lo contains the subsecond fraction. This preserves full precision even for large time values.

For a lossy single f64, use .to_seconds().to_f64().

Source

pub const fn is_negative(&self) -> bool

Returns true if the time delta is negative.

Source

pub const fn is_zero(&self) -> bool

Returns true if the time delta is exactly zero.

Source

pub const fn is_positive(&self) -> bool

Returns true if the time delta is positive.

Source

pub const fn is_finite(&self) -> bool

Returns true if the time delta is a finite value (not NaN or infinite).

Source

pub const fn is_nan(&self) -> bool

Returns true if the time delta is NaN.

Source

pub const fn is_infinite(&self) -> bool

Returns true if the time delta is positive or negative infinity.

Source

pub const fn seconds(&self) -> Option<i64>

Returns the whole seconds component, or None for non-finite values.

Source

pub const fn subsecond(&self) -> Option<f64>

Returns the subsecond fraction as an f64, or None for non-finite values.

Source

pub const fn attoseconds(&self) -> Option<i64>

Returns the attosecond component, or None for non-finite values.

Source

pub const fn add_const(self, rhs: TimeDelta) -> TimeDelta

Adds two TimeDelta values in a const context.

Source

pub const fn sub_const(self, rhs: TimeDelta) -> TimeDelta

Subtracts rhs from self in a const context.

Source

pub const fn mul_const(self, rhs: f64) -> TimeDelta

Multiplies the time delta by an f64 scalar in a const context.

Trait Implementations§

Source§

impl<T: TimeScale> Add<TimeDelta> for Time<T>

Source§

type Output = Time<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: TimeDelta) -> Self::Output

Performs the + operation. Read more
Source§

impl Add for TimeDelta

Source§

type Output = TimeDelta

The resulting type after applying the + operator.
Source§

fn add(self, rhs: TimeDelta) -> <TimeDelta as Add>::Output

Performs the + operation. Read more
Source§

impl AddAssign for TimeDelta

Source§

fn add_assign(&mut self, rhs: TimeDelta)

Performs the += operation. Read more
Source§

impl ApproxEq for TimeDelta

Source§

fn approx_eq(&self, rhs: &TimeDelta, atol: f64, rtol: f64) -> ApproxEqResults

Compares self with rhs for approximate equality. Read more
Source§

impl Clone for TimeDelta

Source§

fn clone(&self) -> TimeDelta

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TimeDelta

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for TimeDelta

Source§

fn default() -> TimeDelta

Returns the “default value” for a type. Read more
Source§

impl Display for TimeDelta

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<f64> for TimeDelta

Source§

fn from(value: f64) -> TimeDelta

Converts to this type from the input type.
Source§

impl From<i32> for TimeDelta

Source§

fn from(value: i32) -> TimeDelta

Converts to this type from the input type.
Source§

impl From<i64> for TimeDelta

Source§

fn from(value: i64) -> TimeDelta

Converts to this type from the input type.
Source§

impl JulianDate for TimeDelta

Source§

fn julian_date(&self, epoch: Epoch, unit: Unit) -> f64

Expresses self as a Julian date in the specified Unit, relative to the given Epoch. Read more
Source§

fn two_part_julian_date(&self) -> (f64, f64)

Expresses self as a two-part Julian date in the specified Unit, relative to the given Epoch. Read more
Source§

fn seconds_since_julian_epoch(&self) -> f64

Returns the number of seconds since the Julian epoch as an f64.
Source§

fn seconds_since_modified_julian_epoch(&self) -> f64

Returns the number of seconds since the Modified Julian epoch as an f64.
Source§

fn seconds_since_j1950(&self) -> f64

Returns the number of seconds since J1950 as an f64.
Source§

fn seconds_since_j2000(&self) -> f64

Returns the number of seconds since J2000 as an f64.
Source§

fn days_since_julian_epoch(&self) -> f64

Returns the number of days since the Julian epoch as an f64.
Source§

fn days_since_modified_julian_epoch(&self) -> f64

Returns the number of days since the Modified Julian epoch as an f64.
Source§

fn days_since_j1950(&self) -> f64

Returns the number of days since J1950 as an f64.
Source§

fn days_since_j2000(&self) -> f64

Returns the number of days since J2000 as an f64.
Source§

fn years_since_julian_epoch(&self) -> f64

Returns the number of years since the Julian epoch as an f64.
Source§

fn years_since_modified_julian_epoch(&self) -> f64

Returns the number of years since the Modified Julian epoch as an f64.
Source§

fn years_since_j1950(&self) -> f64

Returns the number of years since J1950 as an f64.
Source§

fn years_since_j2000(&self) -> f64

Returns the number of years since J2000 as an f64.
Source§

fn centuries_since_julian_epoch(&self) -> f64

Returns the number of centuries since the Julian epoch as an f64.
Source§

fn centuries_since_modified_julian_epoch(&self) -> f64

Returns the number of centuries since the Modified Julian epoch as an f64.
Source§

fn centuries_since_j1950(&self) -> f64

Returns the number of centuries since J1950 as an f64.
Source§

fn centuries_since_j2000(&self) -> f64

Returns the number of centuries since J2000 as an f64.
Source§

impl Neg for TimeDelta

Source§

type Output = TimeDelta

The resulting type after applying the - operator.
Source§

fn neg(self) -> <TimeDelta as Neg>::Output

Performs the unary - operation. Read more
Source§

impl Ord for TimeDelta

Source§

fn cmp(&self, other: &TimeDelta) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for TimeDelta

Source§

fn eq(&self, other: &TimeDelta) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for TimeDelta

Source§

fn partial_cmp(&self, other: &TimeDelta) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: TimeScale> Sub<TimeDelta> for Time<T>

Source§

type Output = Time<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: TimeDelta) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub for TimeDelta

Source§

type Output = TimeDelta

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: TimeDelta) -> <TimeDelta as Sub>::Output

Performs the - operation. Read more
Source§

impl SubAssign for TimeDelta

Source§

fn sub_assign(&mut self, rhs: TimeDelta)

Performs the -= operation. Read more
Source§

impl Copy for TimeDelta

Source§

impl Eq for TimeDelta

Source§

impl StructuralPartialEq for TimeDelta

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.