pub struct Timedelta;Implementations§
Source§impl Timedelta
impl Timedelta
pub const NANOS_PER_MICRO: i64 = 1_000
pub const NANOS_PER_MILLI: i64 = 1_000_000
pub const NANOS_PER_SEC: i64 = 1_000_000_000
pub const NANOS_PER_MIN: i64
pub const NANOS_PER_HOUR: i64
pub const NANOS_PER_DAY: i64
pub const NANOS_PER_WEEK: i64
pub const NAT: i64 = i64::MIN
pub fn parse(s: &str) -> Result<i64, TimedeltaError>
Sourcepub fn unit_to_nanos(unit: &str) -> Option<i64>
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.
pub fn components(nanos: i64) -> TimedeltaComponents
pub fn total_seconds(nanos: i64) -> f64
Sourcepub fn as_unit(nanos: i64, unit: &str) -> f64
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.
Sourcepub fn seconds(nanos: i64) -> i64
pub fn seconds(nanos: i64) -> i64
Return the seconds component (0-86399). Matches pd.Timedelta.seconds.
Sourcepub fn microseconds(nanos: i64) -> i64
pub fn microseconds(nanos: i64) -> i64
Return the microseconds component (0-999999). Matches pd.Timedelta.microseconds.
Sourcepub fn nanoseconds(nanos: i64) -> i64
pub fn nanoseconds(nanos: i64) -> i64
Return the nanoseconds component (0-999). Matches pd.Timedelta.nanoseconds.
pub fn format(nanos: i64) -> String
pub fn from_unit(value: f64, unit: &str) -> Result<i64, TimedeltaError>
Sourcepub fn add(a: i64, b: i64) -> i64
pub fn add(a: i64, b: i64) -> i64
Add two Timedelta nanosecond values. NaT propagates; saturates on overflow.
Sourcepub fn sub(a: i64, b: i64) -> i64
pub fn sub(a: i64, b: i64) -> i64
Subtract two Timedelta nanosecond values. NaT propagates; saturates on overflow.
Sourcepub fn neg(a: i64) -> i64
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).
Sourcepub fn mul_scalar(a: i64, factor: i64) -> i64
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.
Sourcepub fn div_scalar(a: i64, divisor: i64) -> i64
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.
Sourcepub fn div_timedelta(a: i64, b: i64) -> f64
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).
Sourcepub fn isoformat(nanos: i64) -> String
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”.
Sourcepub fn floor(nanos: i64, freq: &str) -> i64
pub fn floor(nanos: i64, freq: &str) -> i64
Rounds down to the nearest frequency unit.
Matches pandas pd.Timedelta.floor(freq). NaT is preserved.