pub struct Timestamp {
pub datetime: DateTime<Utc>,
pub precision: TemporalPrecision,
}Expand description
A timestamp with timezone awareness and precision tracking.
Timestamps in spatial narratives often come from sources with varying precision (e.g., “sometime in March 2024” vs “2024-03-15T14:30:00Z”).
§Examples
use spatial_narrative::core::{Timestamp, TemporalPrecision};
// Current time
let now = Timestamp::now();
// Parse from ISO 8601
let ts = Timestamp::parse("2024-03-15T14:30:00Z").unwrap();
// With explicit precision
let approximate = Timestamp::with_precision(
Timestamp::parse("2024-03-01T00:00:00Z").unwrap().datetime,
TemporalPrecision::Month
);Fields§
§datetime: DateTime<Utc>The datetime in UTC.
precision: TemporalPrecisionThe precision of this timestamp.
Implementations§
Source§impl Timestamp
impl Timestamp
Sourcepub fn new(datetime: DateTime<Utc>) -> Self
pub fn new(datetime: DateTime<Utc>) -> Self
Creates a new timestamp with the given datetime and default (Second) precision.
Sourcepub fn with_precision(
datetime: DateTime<Utc>,
precision: TemporalPrecision,
) -> Self
pub fn with_precision( datetime: DateTime<Utc>, precision: TemporalPrecision, ) -> Self
Creates a new timestamp with explicit precision.
Sourcepub fn parse(s: &str) -> Result<Self>
pub fn parse(s: &str) -> Result<Self>
Parses a timestamp from an ISO 8601 string.
Supported formats:
2024-03-15T14:30:00Z(full precision)2024-03-15T14:30:00+00:00(with timezone offset)2024-03-15(date only, day precision)2024-03(year-month, month precision)2024(year only, year precision)
Sourcepub fn from_unix_millis(millis: i64) -> Option<Self>
pub fn from_unix_millis(millis: i64) -> Option<Self>
Creates a timestamp from Unix epoch milliseconds.
Sourcepub fn unix_timestamp(&self) -> i64
pub fn unix_timestamp(&self) -> i64
Returns the Unix timestamp in seconds.
Sourcepub fn unix_timestamp_millis(&self) -> i64
pub fn unix_timestamp_millis(&self) -> i64
Returns the Unix timestamp in milliseconds.
Sourcepub fn to_unix_millis(&self) -> i64
pub fn to_unix_millis(&self) -> i64
Returns the Unix timestamp in milliseconds (alias for unix_timestamp_millis).
Sourcepub fn to_rfc3339(&self) -> String
pub fn to_rfc3339(&self) -> String
Formats the timestamp as an ISO 8601 string.
Sourcepub fn format_with_precision(&self) -> String
pub fn format_with_precision(&self) -> String
Formats the timestamp according to precision.
Sourcepub fn duration_since(&self, earlier: &Timestamp) -> Duration
pub fn duration_since(&self, earlier: &Timestamp) -> Duration
Returns the duration between this timestamp and another.
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>,
Source§impl Ord for Timestamp
impl Ord for Timestamp
Source§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
impl Eq for Timestamp
impl StructuralPartialEq for Timestamp
Auto Trait Implementations§
impl Freeze for Timestamp
impl RefUnwindSafe for Timestamp
impl Send for Timestamp
impl Sync for Timestamp
impl Unpin for Timestamp
impl UnwindSafe for Timestamp
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.