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: i64Signed whole seconds.
attos: u64Fractional part in attoseconds (0 ≤ attos < 10¹⁸).
Implementations§
Source§impl TSpan
impl TSpan
pub const fn add(self, rhs: Self) -> Self
pub const fn sub(self, rhs: Self) -> Self
Sourcepub const fn to_sec_f(self) -> Real
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).
Sourcepub const fn mul(self, rhs: i64) -> Self
pub const fn mul(self, rhs: i64) -> Self
Multiplies this duration by an integer scalar (exact).
Uses 128-bit arithmetic internally.
Sourcepub const fn div(self, rhs: i64) -> Self
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.
Sourcepub const fn floor(self, unit: TSpan) -> TSpan
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).
Sourcepub const fn ceil(self, unit: TSpan) -> TSpan
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).
Sourcepub const fn round(self, unit: TSpan) -> TSpan
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).
Sourcepub const fn abs_div_floor(self, unit: TSpan) -> usize
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.
Sourcepub const fn mul_by_f(self, rhs: Real) -> Self
pub const fn mul_by_f(self, rhs: Real) -> Self
- Integer part of
rhsis multiplied exactly (pure i128 arithmetic). - Fractional part (|frac| < 1) uses the 10¹⁵ scaling.
Sourcepub const fn div_by_f(self, rhs: Real) -> Self
pub const fn div_by_f(self, rhs: Real) -> Self
Divides by a real number (routes through the high-precision mul_by_f).
Sourcepub const fn add_1sec(&mut self)
pub const fn add_1sec(&mut self)
Adds exactly 1 second to this time value using saturating arithmetic.
Sourcepub const fn add_1min(&mut self)
pub const fn add_1min(&mut self)
Adds exactly 1 minute (60 seconds) to this time value using saturating arithmetic.
Sourcepub const fn add_1hr(&mut self)
pub const fn add_1hr(&mut self)
Adds exactly 1 hour (3600 seconds) to this time value using saturating arithmetic.
Sourcepub const fn add_1ms(&mut self)
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.
Sourcepub const fn add_1us(&mut self)
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.
Sourcepub const fn add_1ns(&mut self)
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.
Sourcepub const fn add_sec(&mut self, n: i64)
pub const fn add_sec(&mut self, n: i64)
Adds the specified number of seconds to this time value using saturating arithmetic.
Sourcepub const fn add_min(&mut self, n: i64)
pub const fn add_min(&mut self, n: i64)
Adds the specified number of minutes to this time value using saturating arithmetic.
Sourcepub const fn add_hr(&mut self, n: i64)
pub const fn add_hr(&mut self, n: i64)
Adds the specified number of hours to this time value using saturating arithmetic.
Sourcepub const fn add_ms(&mut self, n: i64)
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.
Sourcepub const fn add_us(&mut self, n: i64)
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.
Sourcepub const fn add_ns(&mut self, n: i64)
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.
Sourcepub const fn add_ps(&mut self, n: i64)
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.
Sourcepub const fn add_fs(&mut self, n: i64)
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.
Sourcepub const fn add_attos(&mut self, n: i64)
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.
Sourcepub const fn sub_1hr(&mut self)
pub const fn sub_1hr(&mut self)
Subtracts exactly 1 hour (3600 seconds) from this time value using saturating arithmetic.
Sourcepub const fn sub_1min(&mut self)
pub const fn sub_1min(&mut self)
Subtracts exactly 1 minute (60 seconds) from this time value using saturating arithmetic.
Sourcepub const fn sub_1sec(&mut self)
pub const fn sub_1sec(&mut self)
Subtracts exactly 1 second from this time value using saturating arithmetic.
Sourcepub const fn sub_1ms(&mut self)
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.
Sourcepub const fn sub_1us(&mut self)
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.
Sourcepub const fn sub_1ns(&mut self)
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.
Sourcepub const fn sub_sec(&mut self, n: i64)
pub const fn sub_sec(&mut self, n: i64)
Subtracts the specified number of seconds from this time value using saturating arithmetic.
Sourcepub const fn sub_min(&mut self, n: i64)
pub const fn sub_min(&mut self, n: i64)
Subtracts the specified number of minutes from this time value using saturating arithmetic.
Sourcepub const fn sub_hr(&mut self, n: i64)
pub const fn sub_hr(&mut self, n: i64)
Subtracts the specified number of hours from this time value using saturating arithmetic.
Sourcepub const fn sub_ms(&mut self, n: i64)
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.
Sourcepub const fn sub_us(&mut self, n: i64)
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.
Sourcepub const fn sub_ns(&mut self, n: i64)
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.
Sourcepub const fn sub_ps(&mut self, n: i64)
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.
Sourcepub const fn sub_fs(&mut self, n: i64)
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.
Sourcepub const fn sub_attos(&mut self, n: i64)
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.
Sourcepub const fn to_attos(self) -> i128
pub const fn to_attos(self) -> i128
Total attoseconds (exact i128 representation within the representable range).
Sourcepub const fn to_diff(self, rhs: Self) -> Self
pub const fn to_diff(self, rhs: Self) -> Self
Returns self - rhs exactly.
This is the normal case when subtracting two durations.
Sourcepub const fn to_diff_tp(self, rhs: Dt) -> Self
pub const fn to_diff_tp(self, rhs: Dt) -> Self
Returns self - rhs exactly, where rhs is a Dt.
Source§impl TSpan
impl TSpan
pub const SEC_19: Self
pub const SEC_33: Self
pub const SEC_37: Self
pub const ONE_DAY: Self
Sourcepub const fn from_attos(attos: i128) -> Self
pub const fn from_attos(attos: i128) -> Self
Reconstruct TSpan from total attoseconds (exact, handles negative values correctly).
Sourcepub const fn new(sec: i64, attos: u64) -> Self
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¹⁸).
pub const fn from_days(d: i64) -> TSpan
pub const fn wk(wk: i64) -> TSpan
pub const fn yr(yr: i64) -> TSpan
Sourcepub const fn ago(self, scale: Scale) -> Dt
pub const fn ago(self, scale: Scale) -> Dt
Returns a Dt that is this duration ago from the given scale.
Sourcepub const fn from_now(self, scale: Scale) -> Dt
pub const fn from_now(self, scale: Scale) -> Dt
Returns a Dt that is this duration from now in the given scale.
Sourcepub const fn from_hms(
hr: i64,
min: i64,
sec: i64,
ms: i64,
us: i64,
ns: i64,
) -> Self
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.
Sourcepub const fn from_sec_f(sec_f: Real) -> Self
pub const fn from_sec_f(sec_f: Real) -> Self
Creates a TSpan from a floating-point number of seconds.
Source§impl TSpan
impl TSpan
pub fn from_iso(s: &str) -> Result<TSpan, DtErr>
Sourcepub fn looks_like_iso(s: &str) -> bool
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
impl TSpan
Sourcepub const fn cmp(self, other: Self) -> Ordering
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.
Sourcepub const fn min(self, other: Self) -> Self
pub const fn min(self, other: Self) -> Self
Returns the smaller of two TSpans.
This is a const fn.
Sourcepub const fn max(self, other: Self) -> Self
pub const fn max(self, other: Self) -> Self
Returns the larger of two TSpans.
This is a const fn.
Sourcepub const fn lt(self, other: Self) -> bool
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.
Sourcepub const fn gt(self, other: Self) -> bool
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§impl TSpan
impl TSpan
Sourcepub const fn carry_over(&mut self) -> &mut Self
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).
pub const fn to_tai(&self, current: Scale) -> Dt
pub const fn to(&self, current: Scale, target: Scale) -> TSpan
pub const fn to_gregorian_time(&self, current: Scale) -> GregorianTime
pub const fn to_epoch(&self, epoch: Dt, current: Scale) -> Self
Trait Implementations§
Source§impl AddAssign<TSpan> for Dt
impl AddAssign<TSpan> for Dt
Source§fn add_assign(&mut self, rhs: TSpan)
fn add_assign(&mut self, rhs: TSpan)
+= operation. Read moreSource§impl AddAssign for TSpan
impl AddAssign for TSpan
Source§fn add_assign(&mut self, rhs: TSpan)
fn add_assign(&mut self, rhs: TSpan)
Adds a TSpan to this one in place.
Source§impl DivAssign<i64> for TSpan
impl DivAssign<i64> for TSpan
Source§fn div_assign(&mut self, rhs: i64)
fn div_assign(&mut self, rhs: i64)
Divides this TSpan by an integer scalar in place.
Source§impl MulAssign<i64> for TSpan
impl MulAssign<i64> for TSpan
Source§fn mul_assign(&mut self, rhs: i64)
fn mul_assign(&mut self, rhs: i64)
Multiplies this TSpan by an integer scalar in place.
Source§impl Ord for TSpan
impl Ord for TSpan
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for TSpan
impl PartialOrd for TSpan
Source§impl SubAssign<TSpan> for Dt
impl SubAssign<TSpan> for Dt
Source§fn sub_assign(&mut self, rhs: TSpan)
fn sub_assign(&mut self, rhs: TSpan)
-= operation. Read moreSource§impl SubAssign for TSpan
impl SubAssign for TSpan
Source§fn sub_assign(&mut self, rhs: TSpan)
fn sub_assign(&mut self, rhs: TSpan)
Subtracts a TSpan from this one in place.