Skip to main content

Timedelta

Struct Timedelta 

Source
pub struct Timedelta;

Implementations§

Source§

impl Timedelta

Source

pub const NANOS_PER_MICRO: i64 = 1_000

Source

pub const NANOS_PER_MILLI: i64 = 1_000_000

Source

pub const NANOS_PER_SEC: i64 = 1_000_000_000

Source

pub const NANOS_PER_MIN: i64

Source

pub const NANOS_PER_HOUR: i64

Source

pub const NANOS_PER_DAY: i64

Source

pub const NANOS_PER_WEEK: i64

Source

pub const NAT: i64 = i64::MIN

Source

pub fn parse(s: &str) -> Result<i64, TimedeltaError>

Source

pub fn unit_to_nanos(unit: &str) -> Option<i64>

Map a pandas-style frequency-alias string to a nanosecond-count.

Recognizes pandas’s offset alias core set plus common word forms: W/week(s), D/day(s), H/hr/hour(s), m/T/min/minute(s), s/sec/second(s), ms/milli/millisecond(s)/L, us/µs/micro/microsecond(s)/U, ns/nano/ nanosecond(s)/N. Empty string maps to days (matches pandas default). Returns None for unrecognized aliases — callers can choose to map that to NaT (consistent with the rest of fp-types) or surface as a typed error.

Per br-frankenpandas-lbsx (9p0u Phase 2.6): public surface so downstream crates can consume the same alias map fp-types uses for Timedelta::from_unit / Timestamp::*_to_unit.

Source

pub fn components(nanos: i64) -> TimedeltaComponents

Source

pub fn total_seconds(nanos: i64) -> f64

Source

pub fn as_unit(nanos: i64, unit: &str) -> f64

Convert to specified time unit.

Matches pd.Timedelta.as_unit(). Supported units: ns, us, ms, s, m, h, D.

Source

pub fn days(nanos: i64) -> i64

Return the days component. Matches pd.Timedelta.days.

Source

pub fn seconds(nanos: i64) -> i64

Return the seconds component (0-86399). Matches pd.Timedelta.seconds.

Source

pub fn microseconds(nanos: i64) -> i64

Return the microseconds component (0-999999). Matches pd.Timedelta.microseconds.

Source

pub fn nanoseconds(nanos: i64) -> i64

Return the nanoseconds component (0-999). Matches pd.Timedelta.nanoseconds.

Source

pub fn format(nanos: i64) -> String

Source

pub fn from_unit(value: f64, unit: &str) -> Result<i64, TimedeltaError>

Source

pub fn add(a: i64, b: i64) -> i64

Add two Timedelta nanosecond values. NaT propagates; saturates on overflow.

Source

pub fn sub(a: i64, b: i64) -> i64

Subtract two Timedelta nanosecond values. NaT propagates; saturates on overflow.

Source

pub fn neg(a: i64) -> i64

Negate a Timedelta value. NaT stays NaT. Saturates on overflow (pandas: -pd.Timedelta.min is NaT since min == -max - 1 cannot be negated).

Source

pub fn abs(a: i64) -> i64

Absolute value of a Timedelta. NaT stays NaT. Saturates on overflow.

Source

pub fn mul_scalar(a: i64, factor: i64) -> i64

Multiply a Timedelta value by an integer factor. NaT propagates; saturates on overflow.

Matches pandas pd.Timedelta(...) * int.

Source

pub fn div_scalar(a: i64, divisor: i64) -> i64

Floor-divide a Timedelta value by an integer divisor. NaT propagates. Returns NaT on divide-by-zero (matches pandas, which raises, but we surface as NaT to avoid panics at the type-system boundary).

Matches pandas / Python pd.Timedelta(...) // int: floor division, not truncation toward zero. -100 // 3 == -34, and 100 // -3 == -34. Rust’s / truncates toward zero and div_euclid keeps the remainder non-negative — neither matches pandas when the divisor is negative. This helper adjusts trunc-toward-zero into floor.

Source

pub fn div_timedelta(a: i64, b: i64) -> f64

Divide two Timedelta values, returning the ratio as f64. Matches pandas pd.Timedelta(...) / pd.Timedelta(...) → float. NaT in either operand → NaN. Zero divisor → ±Inf (per IEEE 754).

Source

pub fn isoformat(nanos: i64) -> String

Returns ISO 8601 duration format string.

Matches pandas pd.Timedelta.isoformat(). Returns format like “P1DT2H3M4.567890123S” for 1 day, 2 hours, 3 minutes, 4.567890123 seconds. NaT returns “NaT”.

Source

pub fn floor(nanos: i64, freq: &str) -> i64

Rounds down to the nearest frequency unit.

Matches pandas pd.Timedelta.floor(freq). NaT is preserved.

Source

pub fn ceil(nanos: i64, freq: &str) -> i64

Rounds up to the nearest frequency unit.

Matches pandas pd.Timedelta.ceil(freq). NaT is preserved.

Source

pub fn round(nanos: i64, freq: &str) -> i64

Rounds to the nearest frequency unit.

Matches pandas pd.Timedelta.round(freq). Uses banker’s rounding (round half to even). NaT is preserved.

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