Skip to main content

Timestamp

Struct Timestamp 

Source
pub struct Timestamp {
    pub nanos: i64,
    pub tz: Option<String>,
}
Expand description

A nanosecond-precision point in time, Unix-epoch anchored.

Phase 2 scope: construction, arithmetic, equality, ordering, serde. TZ semantics (IANA tz lookup, DST-aware shift) are deferred to Phase 3 — see br-frankenpandas-4r56.

Fields§

§nanos: i64

Nanoseconds since Unix epoch. i64::MIN is NaT.

§tz: Option<String>

Optional IANA time-zone name (e.g. "US/Eastern"). None means naive / UTC-anchored. Phase 2 treats this as opaque metadata; Phase 3 wires chrono_tz interpretation.

Implementations§

Source§

impl Timestamp

Source

pub const NAT: i64 = i64::MIN

NaT sentinel, parallel to Timedelta::NAT.

Source

pub const fn from_nanos(nanos: i64) -> Self

Construct a UTC-anchored (tz=None) Timestamp from nanoseconds since Unix epoch.

Source

pub fn from_nanos_tz(nanos: i64, tz_name: impl Into<String>) -> Self

Construct a Timestamp tagged with an IANA tz name.

Phase 2 doesn’t interpret the tz — it only carries the name through arithmetic + serde. Phase 3 wires chrono_tz conversion.

Source

pub fn now() -> Self

Returns the current UTC timestamp.

Matches pd.Timestamp.now() / pd.Timestamp.utcnow().

Source

pub fn utcnow() -> Self

Alias for now(). Matches pd.Timestamp.utcnow().

Source

pub fn today() -> Self

Returns today’s date at midnight UTC.

Matches pd.Timestamp.today().

Source

pub const fn nat() -> Self

The NaT sentinel value for a Timestamp.

Source

pub const fn is_nat(&self) -> bool

True iff this Timestamp is NaT.

Source

pub const fn value(&self) -> i64

Nanoseconds since Unix epoch, matching pd.Timestamp.value.

Source

pub const fn unit(&self) -> Option<&'static str>

Stored resolution unit, matching pd.Timestamp.unit.

FrankenPandas Timestamp stores nanoseconds internally, so non-NaT values report ns. NaT has no unit.

Source

pub const fn resolution(&self) -> Option<&'static str>

Return the resolution of the timestamp (always “ns” for nanoseconds).

Matches pd.Timestamp.resolution. Returns None for NaT.

Source

pub const fn asm8(&self) -> i64

Numpy datetime64 scalar payload, matching pd.Timestamp.asm8.

Source

pub const fn to_datetime64(&self) -> i64

Convert to a datetime64 payload, matching pd.Timestamp.to_datetime64().

Source

pub const fn to_numpy(&self) -> i64

Convert to a numpy scalar payload, matching pd.Timestamp.to_numpy().

Source

pub fn timestamp(&self) -> Result<f64, TypeError>

POSIX timestamp in seconds, matching pd.Timestamp.timestamp().

Pandas exposes this through Python’s datetime surface, so sub-microsecond nanoseconds are rounded to six decimal places. NaT raises in pandas; fp-types surfaces the same condition as a missing-value error.

Source

pub fn add_timedelta(&self, td_nanos: i64) -> Self

Add a Timedelta. NaT in either operand → NaT; saturates on overflow. TZ is preserved from self.

Source

pub fn sub_timedelta(&self, td_nanos: i64) -> Self

Subtract a Timedelta. NaT propagation + saturation; TZ preserved.

Source

pub fn sub_timestamp(&self, other: &Self) -> i64

Subtract another Timestamp. Returns a Timedelta (i64 nanos). NaT in either → Timedelta::NAT; saturates on overflow.

Source

pub fn semantic_eq(&self, other: &Self) -> bool

NaT-aware semantic equality: two NaT Timestamps are equal to each other (matches pandas pd.NaT == pd.NaT under equals(), though pandas’s == operator returns False for NaT==NaT — we follow the semantic_eq convention used elsewhere in fp-types).

Source

pub fn floor_to(&self, unit_nanos: i64) -> Self

Round down to the nearest multiple of unit_nanos.

Matches pd.Timestamp(...).floor(unit). NaT in self or a non-positive unit_nanos returns NaT.

Source

pub fn ceil_to(&self, unit_nanos: i64) -> Self

Round up to the nearest multiple of unit_nanos.

Matches pd.Timestamp(...).ceil(unit). NaT or non-positive unit_nanos returns NaT. Already-multiple inputs return self.

Source

pub fn round_to(&self, unit_nanos: i64) -> Self

Round to the nearest multiple of unit_nanos, banker’s rounding (half-to-even) on ties.

Matches pd.Timestamp(...).round(unit). NaT or non-positive unit_nanos returns NaT.

Source

pub fn floor_to_unit(&self, unit: &str) -> Self

Round down to the nearest multiple of the named unit.

Matches pd.Timestamp(...).floor(unit). Unknown unit → NaT.

Source

pub fn ceil_to_unit(&self, unit: &str) -> Self

Round up to the nearest multiple of the named unit.

Matches pd.Timestamp(...).ceil(unit). Unknown unit → NaT.

Source

pub fn round_to_unit(&self, unit: &str) -> Self

Round to the nearest multiple of the named unit, banker’s rounding.

Matches pd.Timestamp(...).round(unit). Unknown unit → NaT.

Source

pub fn floor(&self, freq: &str) -> Self

Pandas-named alias for floor_to_unit.

Source

pub fn ceil(&self, freq: &str) -> Self

Pandas-named alias for ceil_to_unit.

Source

pub fn round(&self, freq: &str) -> Self

Pandas-named alias for round_to_unit.

Source

pub fn year(&self) -> Option<i64>

Extract the year component from the timestamp.

Matches pd.Timestamp.year. Returns None for NaT.

Source

pub fn month(&self) -> Option<i64>

Extract the month component (1-12) from the timestamp.

Matches pd.Timestamp.month. Returns None for NaT.

Source

pub fn day(&self) -> Option<i64>

Extract the day component (1-31) from the timestamp.

Matches pd.Timestamp.day. Returns None for NaT.

Source

pub fn hour(&self) -> Option<i64>

Extract the hour component (0-23) from the timestamp.

Matches pd.Timestamp.hour. Returns None for NaT.

Source

pub fn minute(&self) -> Option<i64>

Extract the minute component (0-59) from the timestamp.

Matches pd.Timestamp.minute. Returns None for NaT.

Source

pub fn second(&self) -> Option<i64>

Extract the second component (0-59) from the timestamp.

Matches pd.Timestamp.second. Returns None for NaT.

Source

pub fn microsecond(&self) -> Option<i64>

Extract the microsecond component (0-999999) from the timestamp.

Matches pd.Timestamp.microsecond. Returns None for NaT.

Source

pub fn nanosecond(&self) -> Option<i64>

Extract the nanosecond component (0-999) from the timestamp.

Matches pd.Timestamp.nanosecond. Returns None for NaT.

Source

pub fn dayofweek(&self) -> Option<i64>

Return the day of the week (Monday=0, Sunday=6).

Matches pd.Timestamp.dayofweek. Returns None for NaT.

Source

pub fn weekday(&self) -> Option<i64>

Alias for dayofweek(). Matches pd.Timestamp.weekday.

Source

pub fn day_of_week(&self) -> Option<i64>

Alias for dayofweek(). Matches pd.Timestamp.day_of_week.

Source

pub fn dayofyear(&self) -> Option<i64>

Return the day of the year (1-366).

Matches pd.Timestamp.dayofyear. Returns None for NaT.

Source

pub fn day_of_year(&self) -> Option<i64>

Alias for dayofyear(). Matches pd.Timestamp.day_of_year.

Source

pub fn toordinal(&self) -> Option<i64>

Return the proleptic Gregorian ordinal (number of days since Jan 1, year 1).

Matches pd.Timestamp.toordinal(). Returns None for NaT.

Source

pub fn fromordinal(ordinal: i64) -> Self

Construct a Timestamp from a proleptic Gregorian ordinal.

Matches pd.Timestamp.fromordinal(ordinal). Returns NaT for invalid ordinals.

Source

pub fn to_julian_date(&self) -> f64

Return the Julian Date (astronomical day number).

Matches pd.Timestamp.to_julian_date(). Returns NaN for NaT. The Julian Date is the continuous count of days since the beginning of the Julian Period (January 1, 4713 BC in the proleptic Julian calendar).

Source

pub fn quarter(&self) -> Option<i64>

Return the quarter (1-4) of the year.

Matches pd.Timestamp.quarter. Returns None for NaT.

Source

pub fn weekofyear(&self) -> Option<i64>

Return the ISO week number (1-53).

Matches pd.Timestamp.week. Returns None for NaT.

Source

pub fn week(&self) -> Option<i64>

Alias for weekofyear(). Matches pd.Timestamp.week.

Source

pub fn to_unit(&self, unit: &str) -> Option<i64>

Return the timestamp value in the specified unit.

Matches pd.Timestamp.value when unit is nanoseconds. Supported units: “ns”, “us”, “ms”, “s”.

Source

pub fn is_leap_year(&self) -> Option<bool>

Whether the year is a leap year.

Matches pd.Timestamp.is_leap_year. Returns None for NaT.

Source

pub fn is_month_start(&self) -> Option<bool>

Whether the day is the first day of the month.

Matches pd.Timestamp.is_month_start. Returns None for NaT.

Source

pub fn is_month_end(&self) -> Option<bool>

Whether the day is the last day of the month.

Matches pd.Timestamp.is_month_end. Returns None for NaT.

Source

pub fn is_quarter_start(&self) -> Option<bool>

Whether the day is the first day of a quarter.

Matches pd.Timestamp.is_quarter_start. Returns None for NaT.

Source

pub fn is_quarter_end(&self) -> Option<bool>

Whether the day is the last day of a quarter.

Matches pd.Timestamp.is_quarter_end. Returns None for NaT.

Source

pub fn is_year_start(&self) -> Option<bool>

Whether the day is the first day of the year (Jan 1).

Matches pd.Timestamp.is_year_start. Returns None for NaT.

Source

pub fn is_year_end(&self) -> Option<bool>

Whether the day is the last day of the year (Dec 31).

Matches pd.Timestamp.is_year_end. Returns None for NaT.

Source

pub fn days_in_month(&self) -> Option<i64>

Return the number of days in the month of this timestamp.

Matches pd.Timestamp.days_in_month. Returns None for NaT.

Source

pub fn daysinmonth(&self) -> Option<i64>

Alias for days_in_month(). Matches pd.Timestamp.daysinmonth.

Source

pub fn normalize(&self) -> Self

Normalize to midnight/day boundary, matching pd.Timestamp.normalize().

Source

pub fn replace( &self, year: Option<i64>, month: Option<i64>, day: Option<i64>, hour: Option<i64>, minute: Option<i64>, second: Option<i64>, microsecond: Option<i64>, nanosecond: Option<i64>, ) -> Self

Replace timestamp components with new values.

Matches pd.Timestamp.replace(). None values keep the existing component.

Source

pub fn isoformat(&self) -> String

Return an ISO 8601 string representation of the timestamp.

Matches pd.Timestamp.isoformat(). NaT returns “NaT”.

Source

pub fn to_iso8601(&self) -> String

Alias for isoformat.

Source

pub fn parse(s: &str) -> Result<Self, TypeError>

Parse a datetime string into a Timestamp.

Supports ISO 8601 formats:

  • “2024-01-15” (date only, time defaults to 00:00:00)
  • “2024-01-15T10:30:00” (datetime)
  • “2024-01-15 10:30:00” (space separator)
  • “2024-01-15T10:30:00.123456” (with fractional seconds)
  • “2024-01-15T10:30:00Z” (UTC timezone)
  • “2024-01-15T10:30:00+05:30” (offset timezone)
  • “NaT” (Not a Timestamp)

Matches pd.Timestamp() constructor behavior.

Source

pub fn strftime(&self, format: &str) -> String

Format timestamp using strftime directives.

Matches pd.Timestamp.strftime(format). Supports: %Y (year), %m (month), %d (day), %H (hour), %M (minute), %S (second), %f (microsecond). NaT returns “NaT”.

Source

pub fn day_name(&self) -> String

Return the day of the week as a string (e.g., “Monday”).

Matches pd.Timestamp.day_name(). NaT returns “NaT”.

Source

pub fn month_name(&self) -> String

Return the month name as a string (e.g., “January”).

Matches pd.Timestamp.month_name(). NaT returns “NaT”.

Source

pub fn tz_localize(&self, tz: Option<&str>) -> Self

Localize a naive timestamp to a timezone.

Matches pd.Timestamp.tz_localize(tz). If tz is None, removes the timezone (makes timestamp naive). NaT propagates.

Source

pub fn tz_convert(&self, tz: &str) -> Self

Convert timezone-aware timestamp to another timezone.

Matches pd.Timestamp.tz_convert(tz). If timestamp is naive (no tz), the timezone is simply attached without conversion. NaT propagates. Note: actual UTC offset conversion requires chrono-tz (Phase 3).

Source

pub fn fromtimestamp(ts: f64, tz: Option<&str>) -> Self

Create a Timestamp from a Unix timestamp (seconds since epoch).

Matches pd.Timestamp.fromtimestamp(ts). The optional tz parameter specifies the timezone to localize to.

Source

pub fn from_millis(ms: i64, tz: Option<&str>) -> Self

Create a Timestamp from milliseconds since epoch.

Convenience constructor complementing fromtimestamp.

Source

pub fn from_micros(us: i64, tz: Option<&str>) -> Self

Create a Timestamp from microseconds since epoch.

Convenience constructor complementing fromtimestamp.

Source

pub fn tzinfo(&self) -> Option<&str>

Return the timezone string, or None if naive.

Source

pub fn tzname(&self) -> Option<&str>

Return the timezone name, or None if naive.

Alias for tzinfo() matching pandas Timestamp.tzname().

Trait Implementations§

Source§

impl Clone for Timestamp

Source§

fn clone(&self) -> Timestamp

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 Timestamp

Source§

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

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

impl<'de> Deserialize<'de> for Timestamp

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Timestamp

Source§

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

Phase 2 debug-style format; Phase 3 replaces with pandas ISO-8601 notation once chrono interpretation lands.

Source§

impl Eq for Timestamp

Source§

impl Hash for Timestamp

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 PartialEq for Timestamp

Source§

fn eq(&self, other: &Timestamp) -> 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 Timestamp

Source§

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

Orders by nanos axis; NaT is incomparable (None). Tz difference does not affect ordering — two Timestamps at the same absolute nanos compare equal regardless of tz label (Phase 3 will revisit whether tz affects ordering semantics).

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 Serialize for Timestamp

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Timestamp

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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