Skip to main content

TSpan

Struct TSpan 

Source
pub struct TSpan {
    pub sec: i64,
    pub attos: u64,
}
Expand description

A high-precision duration (time span) expressed as seconds + attoseconds (where 1 attosecond = 10⁻¹⁸ s).

TSpan is the time span counterpart of Dt.

  • Precision: 10⁻¹⁸ s
  • Range: ±~292 billion years (i64 seconds limit).

Fields§

§sec: i64

Signed whole seconds.

§attos: u64

Fractional part in attoseconds (0 ≤ attos < 10¹⁸).

Implementations§

Source§

impl TSpan

Source

pub const fn add(self, rhs: Self) -> Self

Source

pub const fn sub(self, rhs: Self) -> Self

Source

pub const fn is_zero(self) -> bool

Returns true if this duration is exactly zero.

Source

pub const fn to_sec_f(self) -> Real

Converts this duration to a floating-point number of seconds. It computes sec + attos / 10¹⁸ using f64. It is lossy by design (f64 only has ~15.95 decimal digits of precision).

Source

pub const fn mul(self, rhs: i64) -> Self

Multiplies this duration by an integer scalar (exact).

Uses 128-bit arithmetic internally.

Source

pub const fn div(self, rhs: i64) -> Self

Divides this duration by an integer scalar (exact floor division).

Returns ZERO if rhs == 0. Uses floor division (toward negative infinity) for consistency with the existing floor method.

Source

pub const fn floor(self, unit: TSpan) -> TSpan

Returns the largest multiple of unit that is ≤ self. If unit is zero, returns self unchanged (exact, full precision).

Source

pub const fn ceil(self, unit: TSpan) -> TSpan

Returns the smallest multiple of unit that is ≥ self. If unit is zero, returns self unchanged (exact, full precision).

Source

pub const fn round(self, unit: TSpan) -> TSpan

Returns the nearest multiple of unit. Halfway cases round away from zero (matches old f64::round). If unit is zero, returns self unchanged (exact, full precision).

Source

pub const fn abs_div_floor(self, unit: TSpan) -> usize

Returns floor(|self| / |unit|) as usize, saturating at usize::MAX.

Fully exact integer arithmetic using 128-bit intermediaries. Used by TimeRange::len.

Source

pub const fn mul_by_f(self, rhs: Real) -> Self

  • Integer part of rhs is multiplied exactly (pure i128 arithmetic).
  • Fractional part (|frac| < 1) uses the 10¹⁵ scaling.
Source

pub const fn div_by_f(self, rhs: Real) -> Self

Divides by a real number (routes through the high-precision mul_by_f).

Source

pub const fn div_by_2(self) -> TSpan

Divides this duration by 2 (convenience wrapper).

Source

pub const fn add_1sec(&mut self)

Adds exactly 1 second to this time value using saturating arithmetic.

Source

pub const fn add_1min(&mut self)

Adds exactly 1 minute (60 seconds) to this time value using saturating arithmetic.

Source

pub const fn add_1hr(&mut self)

Adds exactly 1 hour (3600 seconds) to this time value using saturating arithmetic.

Source

pub const fn add_1ms(&mut self)

Adds exactly 1 millisecond to this time value.

This affects the subsecond component and may cause a carry into the seconds field.

Source

pub const fn add_1us(&mut self)

Adds exactly 1 microsecond to this time value.

This affects the subsecond component and may cause a carry into the seconds field.

Source

pub const fn add_1ns(&mut self)

Adds exactly 1 nanosecond to this time value.

This affects the subsecond component and may cause a carry into the seconds field.

Source

pub const fn add_sec(&mut self, n: i64)

Adds the specified number of seconds to this time value using saturating arithmetic.

Source

pub const fn add_min(&mut self, n: i64)

Adds the specified number of minutes to this time value using saturating arithmetic.

Source

pub const fn add_hr(&mut self, n: i64)

Adds the specified number of hours to this time value using saturating arithmetic.

Source

pub const fn add_ms(&mut self, n: i64)

Adds the specified number of milliseconds to this time value.

Handles carry into the seconds field using saturating logic.

Source

pub const fn add_us(&mut self, n: i64)

Adds the specified number of microseconds to this time value.

Handles carry into the seconds field using saturating logic.

Source

pub const fn add_ns(&mut self, n: i64)

Adds the specified number of nanoseconds to this time value.

Handles carry into the seconds field using saturating logic.

Source

pub const fn add_ps(&mut self, n: i64)

Adds the specified number of picoseconds to this time value.

Handles carry into the seconds field using saturating logic.

Source

pub const fn add_fs(&mut self, n: i64)

Adds the specified number of femtoseconds to this time value.

Handles carry into the seconds field using saturating logic.

Source

pub const fn add_attos(&mut self, n: i64)

Adds the specified number of attoseconds to this time value.

Handles carry into the seconds field using saturating logic.

Source

pub const fn sub_1hr(&mut self)

Subtracts exactly 1 hour (3600 seconds) from this time value using saturating arithmetic.

Source

pub const fn sub_1min(&mut self)

Subtracts exactly 1 minute (60 seconds) from this time value using saturating arithmetic.

Source

pub const fn sub_1sec(&mut self)

Subtracts exactly 1 second from this time value using saturating arithmetic.

Source

pub const fn sub_1ms(&mut self)

Subtracts exactly 1 millisecond from this time value.

This affects the subsecond component and may cause a borrow from the seconds field.

Source

pub const fn sub_1us(&mut self)

Subtracts exactly 1 microsecond from this time value.

This affects the subsecond component and may cause a borrow from the seconds field.

Source

pub const fn sub_1ns(&mut self)

Subtracts exactly 1 nanosecond from this time value.

This affects the subsecond component and may cause a borrow from the seconds field.

Source

pub const fn sub_sec(&mut self, n: i64)

Subtracts the specified number of seconds from this time value using saturating arithmetic.

Source

pub const fn sub_min(&mut self, n: i64)

Subtracts the specified number of minutes from this time value using saturating arithmetic.

Source

pub const fn sub_hr(&mut self, n: i64)

Subtracts the specified number of hours from this time value using saturating arithmetic.

Source

pub const fn sub_ms(&mut self, n: i64)

Subtracts the specified number of milliseconds from this time value.

Handles borrow from the seconds field using saturating logic.

Source

pub const fn sub_us(&mut self, n: i64)

Subtracts the specified number of microseconds from this time value.

Handles borrow from the seconds field using saturating logic.

Source

pub const fn sub_ns(&mut self, n: i64)

Subtracts the specified number of nanoseconds from this time value.

Handles borrow from the seconds field using saturating logic.

Source

pub const fn sub_ps(&mut self, n: i64)

Subtracts the specified number of picoseconds from this time value.

Handles borrow from the seconds field using saturating logic.

Source

pub const fn sub_fs(&mut self, n: i64)

Subtracts the specified number of femtoseconds from this time value.

Handles borrow from the seconds field using saturating logic.

Source

pub const fn sub_attos(&mut self, n: i64)

Subtracts the specified number of attoseconds from this time value.

Handles borrow from the seconds field using saturating logic.

Source

pub const fn to_attos(self) -> i128

Total attoseconds (exact i128 representation within the representable range).

Source

pub const fn to_sec(&mut self) -> i64

Returns the total duration in seconds.

Source

pub const fn to_ms(self) -> i128

Returns the total duration in milliseconds.

Source

pub const fn to_us(self) -> i128

Returns the total duration in microseconds.

Source

pub const fn to_ns(self) -> i128

Returns the total duration in nanoseconds.

Source

pub const fn to_ps(self) -> i128

Returns the total duration in picoseconds.

Source

pub const fn to_fs(self) -> i128

Returns the total duration in femtoseconds.

Source

pub const fn to_diff(self, rhs: Self) -> Self

Returns self - rhs exactly.

This is the normal case when subtracting two durations.

Source

pub const fn to_diff_tp(self, rhs: Dt) -> Self

Returns self - rhs exactly, where rhs is a Dt.

Source§

impl TSpan

Source

pub const ZERO: Self

Zero duration (0 s).

Source

pub const MAX: Self

Maximum representable duration (i64::MAX seconds + 999… attoseconds).

Source

pub const MIN: Self

Minimum (most negative) representable duration (i64::MIN seconds).

Source

pub const SEC_19: Self

Source

pub const SEC_33: Self

Source

pub const SEC_37: Self

Source

pub const ONE_DAY: Self

Source

pub const fn from_attos(attos: i128) -> Self

Reconstruct TSpan from total attoseconds (exact, handles negative values correctly).

Source

pub const fn new(sec: i64, attos: u64) -> Self

Creates a new TSpan from whole seconds and a subsecond part.

The result is automatically normalized so attos lies in [0, 10¹⁸).

Source

pub const fn from_sec(s: i64) -> Self

Creates a TSpan representing s seconds.

Source

pub const fn from_ms(ms: i128) -> Self

Creates a TSpan representing ms milliseconds.

Source

pub const fn from_us(us: i128) -> Self

Creates a TSpan representing us microseconds.

Source

pub const fn from_ns(ns: i128) -> Self

Creates a TSpan representing ns nanoseconds.

Source

pub const fn from_ps(ps: i128) -> Self

Creates a TSpan representing ps picoseconds.

Source

pub const fn from_fs(fs: i128) -> Self

Creates a TSpan representing fs femtoseconds.

Source

pub const fn from_min(m: i64) -> Self

Creates a TSpan representing m minutes.

Source

pub const fn from_hr(h: i64) -> Self

Creates a TSpan representing h hours.

Source

pub const fn from_days(d: i64) -> TSpan

Source

pub const fn wk(wk: i64) -> TSpan

Source

pub const fn yr(yr: i64) -> TSpan

Source

pub const fn ago(self, scale: Scale) -> Dt

Returns a Dt that is this duration ago from the given scale.

Source

pub const fn from_now(self, scale: Scale) -> Dt

Returns a Dt that is this duration from now in the given scale.

Source

pub const fn from_hms( hr: i64, min: i64, sec: i64, ms: i64, us: i64, ns: i64, ) -> Self

Creates a TSpan from hours, minutes, seconds, milliseconds, microseconds, and nanoseconds.

Source

pub const fn neg(self) -> Self

Returns the negation of this duration.

Source

pub const fn from_sec_f(sec_f: Real) -> Self

Creates a TSpan from a floating-point number of seconds.

Source§

impl TSpan

Source

pub fn from_iso(s: &str) -> Result<TSpan, DtErr>

Source

pub fn looks_like_iso(s: &str) -> bool

Accepts: P1Y, -P2W, PT1.5H, P1DT2H30M, +P3D, p1y, P1,5S, PT0S, etc. Rejects: anything with whitespace, lone “P”/“-P”/“PT”, “P123”, “Please wait 5m”, “1.5h”, “P1Yabc”, “P1Y!”, or any string longer than 128 bytes.

Source§

impl TSpan

Source

pub const fn cmp(self, other: Self) -> Ordering

Compares two TSpans by their (sec, attos) representation.

This is a const fn so it can be used in const contexts.

Source

pub const fn min(self, other: Self) -> Self

Returns the smaller of two TSpans.

This is a const fn.

Source

pub const fn max(self, other: Self) -> Self

Returns the larger of two TSpans.

This is a const fn.

Source

pub const fn lt(self, other: Self) -> bool

Returns true if this TSpan is less than the other.

This is a const fn so it can be used in const contexts.

Source

pub const fn gt(self, other: Self) -> bool

Returns true if this TSpan is greater than the other.

This is a const fn so it can be used in const contexts.

Source

pub const fn le(self, other: Self) -> bool

Returns true if this TSpan is less than or equal to the other.

This is a const fn so it can be used in const contexts.

Source

pub const fn ge(self, other: Self) -> bool

Returns true if this TSpan is greater than or equal to the other.

This is a const fn so it can be used in const contexts.

Source§

impl TSpan

Source

pub const fn sec(&self) -> i64

Seconds field getter.

Source

pub const fn attos(&self) -> u64

Subseconds field getter (attoseconds).

Source

pub const fn carry_over(&mut self) -> &mut Self

Normalizes the representation so that the attosecond part lies in the range [0, ATTOS_PER_SEC).

Source

pub const fn to_tai(&self, current: Scale) -> Dt

Source

pub const fn to(&self, current: Scale, target: Scale) -> TSpan

Source

pub const fn to_gregorian_time(&self, current: Scale) -> GregorianTime

Source

pub const fn to_epoch(&self, epoch: Dt, current: Scale) -> Self

Trait Implementations§

Source§

impl Add<TSpan> for Dt

Source§

type Output = Dt

The resulting type after applying the + operator.
Source§

fn add(self, rhs: TSpan) -> Self

Performs the + operation. Read more
Source§

impl Add for TSpan

Source§

fn add(self, rhs: TSpan) -> Self

Adds two TSpans.

Source§

type Output = TSpan

The resulting type after applying the + operator.
Source§

impl AddAssign<TSpan> for Dt

Source§

fn add_assign(&mut self, rhs: TSpan)

Performs the += operation. Read more
Source§

impl AddAssign for TSpan

Source§

fn add_assign(&mut self, rhs: TSpan)

Adds a TSpan to this one in place.

Source§

impl Clone for TSpan

Source§

fn clone(&self) -> TSpan

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TSpan

Source§

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

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

impl Default for TSpan

Source§

fn default() -> Self

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

impl Display for TSpan

Source§

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

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

impl Div<i64> for TSpan

Source§

fn div(self, rhs: i64) -> Self

Divides this TSpan by an integer scalar.

Source§

type Output = TSpan

The resulting type after applying the / operator.
Source§

impl DivAssign<i64> for TSpan

Source§

fn div_assign(&mut self, rhs: i64)

Divides this TSpan by an integer scalar in place.

Source§

impl Hash for TSpan

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Mul<i64> for TSpan

Source§

fn mul(self, rhs: i64) -> Self

Multiplies this TSpan by an integer scalar.

Source§

type Output = TSpan

The resulting type after applying the * operator.
Source§

impl MulAssign<i64> for TSpan

Source§

fn mul_assign(&mut self, rhs: i64)

Multiplies this TSpan by an integer scalar in place.

Source§

impl Neg for TSpan

Source§

fn neg(self) -> Self

Negates this TSpan (returns the additive inverse).

Source§

type Output = TSpan

The resulting type after applying the - operator.
Source§

impl Ord for TSpan

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · 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 TSpan

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 TSpan

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 Sub<TSpan> for Dt

Source§

type Output = Dt

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: TSpan) -> Self

Performs the - operation. Read more
Source§

impl Sub for TSpan

Source§

fn sub(self, rhs: TSpan) -> Self

Subtracts a TSpan from this one.

Source§

type Output = TSpan

The resulting type after applying the - operator.
Source§

impl SubAssign<TSpan> for Dt

Source§

fn sub_assign(&mut self, rhs: TSpan)

Performs the -= operation. Read more
Source§

impl SubAssign for TSpan

Source§

fn sub_assign(&mut self, rhs: TSpan)

Subtracts a TSpan from this one in place.

Source§

impl Copy for TSpan

Source§

impl Eq for TSpan

Source§

impl StructuralPartialEq for TSpan

Auto Trait Implementations§

§

impl Freeze for TSpan

§

impl RefUnwindSafe for TSpan

§

impl Send for TSpan

§

impl Sync for TSpan

§

impl Unpin for TSpan

§

impl UnsafeUnpin for TSpan

§

impl UnwindSafe for TSpan

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, 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.