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: i64Nanoseconds 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
impl Timestamp
Sourcepub const fn from_nanos(nanos: i64) -> Self
pub const fn from_nanos(nanos: i64) -> Self
Construct a UTC-anchored (tz=None) Timestamp from nanoseconds since Unix epoch.
Sourcepub fn from_nanos_tz(nanos: i64, tz_name: impl Into<String>) -> Self
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.
Sourcepub fn now() -> Self
pub fn now() -> Self
Returns the current UTC timestamp.
Matches pd.Timestamp.now() / pd.Timestamp.utcnow().
Sourcepub const fn unit(&self) -> Option<&'static str>
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.
Sourcepub const fn resolution(&self) -> Option<&'static str>
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.
Sourcepub const fn to_datetime64(&self) -> i64
pub const fn to_datetime64(&self) -> i64
Convert to a datetime64 payload, matching pd.Timestamp.to_datetime64().
Sourcepub const fn to_numpy(&self) -> i64
pub const fn to_numpy(&self) -> i64
Convert to a numpy scalar payload, matching pd.Timestamp.to_numpy().
Sourcepub fn timestamp(&self) -> Result<f64, TypeError>
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.
Sourcepub fn add_timedelta(&self, td_nanos: i64) -> Self
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.
Sourcepub fn sub_timedelta(&self, td_nanos: i64) -> Self
pub fn sub_timedelta(&self, td_nanos: i64) -> Self
Subtract a Timedelta. NaT propagation + saturation; TZ preserved.
Sourcepub fn sub_timestamp(&self, other: &Self) -> i64
pub fn sub_timestamp(&self, other: &Self) -> i64
Subtract another Timestamp. Returns a Timedelta (i64 nanos).
NaT in either → Timedelta::NAT; saturates on overflow.
Sourcepub fn semantic_eq(&self, other: &Self) -> bool
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).
Sourcepub fn floor_to(&self, unit_nanos: i64) -> Self
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.
Sourcepub fn ceil_to(&self, unit_nanos: i64) -> Self
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.
Sourcepub fn round_to(&self, unit_nanos: i64) -> Self
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.
Sourcepub fn floor_to_unit(&self, unit: &str) -> Self
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.
Sourcepub fn ceil_to_unit(&self, unit: &str) -> Self
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.
Sourcepub fn round_to_unit(&self, unit: &str) -> Self
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.
Sourcepub fn floor(&self, freq: &str) -> Self
pub fn floor(&self, freq: &str) -> Self
Pandas-named alias for floor_to_unit.
Sourcepub fn ceil(&self, freq: &str) -> Self
pub fn ceil(&self, freq: &str) -> Self
Pandas-named alias for ceil_to_unit.
Sourcepub fn round(&self, freq: &str) -> Self
pub fn round(&self, freq: &str) -> Self
Pandas-named alias for round_to_unit.
Sourcepub fn year(&self) -> Option<i64>
pub fn year(&self) -> Option<i64>
Extract the year component from the timestamp.
Matches pd.Timestamp.year. Returns None for NaT.
Sourcepub fn month(&self) -> Option<i64>
pub fn month(&self) -> Option<i64>
Extract the month component (1-12) from the timestamp.
Matches pd.Timestamp.month. Returns None for NaT.
Sourcepub fn day(&self) -> Option<i64>
pub fn day(&self) -> Option<i64>
Extract the day component (1-31) from the timestamp.
Matches pd.Timestamp.day. Returns None for NaT.
Sourcepub fn hour(&self) -> Option<i64>
pub fn hour(&self) -> Option<i64>
Extract the hour component (0-23) from the timestamp.
Matches pd.Timestamp.hour. Returns None for NaT.
Sourcepub fn minute(&self) -> Option<i64>
pub fn minute(&self) -> Option<i64>
Extract the minute component (0-59) from the timestamp.
Matches pd.Timestamp.minute. Returns None for NaT.
Sourcepub fn second(&self) -> Option<i64>
pub fn second(&self) -> Option<i64>
Extract the second component (0-59) from the timestamp.
Matches pd.Timestamp.second. Returns None for NaT.
Sourcepub fn microsecond(&self) -> Option<i64>
pub fn microsecond(&self) -> Option<i64>
Extract the microsecond component (0-999999) from the timestamp.
Matches pd.Timestamp.microsecond. Returns None for NaT.
Sourcepub fn nanosecond(&self) -> Option<i64>
pub fn nanosecond(&self) -> Option<i64>
Extract the nanosecond component (0-999) from the timestamp.
Matches pd.Timestamp.nanosecond. Returns None for NaT.
Sourcepub fn dayofweek(&self) -> Option<i64>
pub fn dayofweek(&self) -> Option<i64>
Return the day of the week (Monday=0, Sunday=6).
Matches pd.Timestamp.dayofweek. Returns None for NaT.
Sourcepub fn day_of_week(&self) -> Option<i64>
pub fn day_of_week(&self) -> Option<i64>
Alias for dayofweek(). Matches pd.Timestamp.day_of_week.
Sourcepub fn dayofyear(&self) -> Option<i64>
pub fn dayofyear(&self) -> Option<i64>
Return the day of the year (1-366).
Matches pd.Timestamp.dayofyear. Returns None for NaT.
Sourcepub fn day_of_year(&self) -> Option<i64>
pub fn day_of_year(&self) -> Option<i64>
Alias for dayofyear(). Matches pd.Timestamp.day_of_year.
Sourcepub fn toordinal(&self) -> Option<i64>
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.
Sourcepub fn fromordinal(ordinal: i64) -> Self
pub fn fromordinal(ordinal: i64) -> Self
Construct a Timestamp from a proleptic Gregorian ordinal.
Matches pd.Timestamp.fromordinal(ordinal). Returns NaT for invalid ordinals.
Sourcepub fn to_julian_date(&self) -> f64
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).
Sourcepub fn quarter(&self) -> Option<i64>
pub fn quarter(&self) -> Option<i64>
Return the quarter (1-4) of the year.
Matches pd.Timestamp.quarter. Returns None for NaT.
Sourcepub fn weekofyear(&self) -> Option<i64>
pub fn weekofyear(&self) -> Option<i64>
Return the ISO week number (1-53).
Matches pd.Timestamp.week. Returns None for NaT.
Sourcepub fn to_unit(&self, unit: &str) -> Option<i64>
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”.
Sourcepub fn is_leap_year(&self) -> Option<bool>
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.
Sourcepub fn is_month_start(&self) -> Option<bool>
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.
Sourcepub fn is_month_end(&self) -> Option<bool>
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.
Sourcepub fn is_quarter_start(&self) -> Option<bool>
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.
Sourcepub fn is_quarter_end(&self) -> Option<bool>
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.
Sourcepub fn is_year_start(&self) -> Option<bool>
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.
Sourcepub fn is_year_end(&self) -> Option<bool>
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.
Sourcepub fn days_in_month(&self) -> Option<i64>
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.
Sourcepub fn daysinmonth(&self) -> Option<i64>
pub fn daysinmonth(&self) -> Option<i64>
Alias for days_in_month(). Matches pd.Timestamp.daysinmonth.
Sourcepub fn normalize(&self) -> Self
pub fn normalize(&self) -> Self
Normalize to midnight/day boundary, matching pd.Timestamp.normalize().
Sourcepub 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
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.
Sourcepub fn isoformat(&self) -> String
pub fn isoformat(&self) -> String
Return an ISO 8601 string representation of the timestamp.
Matches pd.Timestamp.isoformat(). NaT returns “NaT”.
Sourcepub fn to_iso8601(&self) -> String
pub fn to_iso8601(&self) -> String
Alias for isoformat.
Sourcepub fn parse(s: &str) -> Result<Self, TypeError>
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.
Sourcepub fn strftime(&self, format: &str) -> String
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”.
Sourcepub fn day_name(&self) -> String
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”.
Sourcepub fn month_name(&self) -> String
pub fn month_name(&self) -> String
Return the month name as a string (e.g., “January”).
Matches pd.Timestamp.month_name(). NaT returns “NaT”.
Sourcepub fn tz_localize(&self, tz: Option<&str>) -> Self
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.
Sourcepub fn tz_convert(&self, tz: &str) -> Self
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).
Sourcepub fn fromtimestamp(ts: f64, tz: Option<&str>) -> Self
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.
Sourcepub fn from_millis(ms: i64, tz: Option<&str>) -> Self
pub fn from_millis(ms: i64, tz: Option<&str>) -> Self
Create a Timestamp from milliseconds since epoch.
Convenience constructor complementing fromtimestamp.
Sourcepub fn from_micros(us: i64, tz: Option<&str>) -> Self
pub fn from_micros(us: i64, tz: Option<&str>) -> Self
Create a Timestamp from microseconds since epoch.
Convenience constructor complementing fromtimestamp.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Timestamp
impl<'de> Deserialize<'de> for Timestamp
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Timestamp
Source§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
Source§fn partial_cmp(&self, other: &Self) -> Option<Ordering>
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).