Struct proof_of_sql_parser::posql_time::PoSQLTimestamp
source · pub struct PoSQLTimestamp { /* private fields */ }
Expand description
Defines an RFC3339-formatted timestamp Represents a fully parsed timestamp with detailed time unit and timezone information
Implementations§
source§impl PoSQLTimestamp
impl PoSQLTimestamp
sourcepub fn timeunit(&self) -> PoSQLTimeUnit
pub fn timeunit(&self) -> PoSQLTimeUnit
Returns the PoSQLTimeUnit for this timestamp
sourcepub fn timezone(&self) -> PoSQLTimeZone
pub fn timezone(&self) -> PoSQLTimeZone
Returns the PoSQLTimeZone for this timestamp
sourcepub fn try_from(timestamp_str: &str) -> Result<Self, PoSQLTimestampError>
pub fn try_from(timestamp_str: &str) -> Result<Self, PoSQLTimestampError>
Attempts to parse a timestamp string into an PoSQLTimestamp structure. This function supports two primary formats:
-
RFC 3339 Parsing:
- Parses the timestamp along with its timezone.
- If parsing succeeds, it extracts the timezone offset using
dt.offset().local_minus_utc()
and then uses this to construct the appropriatePoSQLTimeZone
.
-
Timezone Parsing and Conversion:
- The
from_offset
method is used to determine whether the timezone should be represented asUtc
orFixedOffset
. This function simplifies the decision based on the offset value.
- The
§Examples
use chrono::{DateTime, Utc};
use proof_of_sql_parser::posql_time::{PoSQLTimestamp, PoSQLTimeZone};
// Parsing an RFC 3339 timestamp without a timezone:
let timestamp_str = "2009-01-03T18:15:05Z";
let intermediate_timestamp = PoSQLTimestamp::try_from(timestamp_str).unwrap();
assert_eq!(intermediate_timestamp.timezone(), PoSQLTimeZone::Utc);
// Parsing an RFC 3339 timestamp with a positive timezone offset:
let timestamp_str_with_tz = "2009-01-03T18:15:05+03:00";
let intermediate_timestamp = PoSQLTimestamp::try_from(timestamp_str_with_tz).unwrap();
assert_eq!(intermediate_timestamp.timezone(), PoSQLTimeZone::FixedOffset(10800)); // 3 hours in seconds
sourcepub fn to_timestamp(epoch: i64) -> Result<Self, PoSQLTimestampError>
pub fn to_timestamp(epoch: i64) -> Result<Self, PoSQLTimestampError>
Attempts to parse a timestamp string into an PoSQLTimestamp
structure.
This function supports two primary formats:
Unix Epoch Time Parsing:
- Since Unix epoch timestamps don’t inherently carry timezone information, any Unix time parsed directly from an integer is assumed to be in UTC.
§Examples
use chrono::{DateTime, Utc};
use proof_of_sql_parser::posql_time::{PoSQLTimestamp, PoSQLTimeZone};
// Parsing a Unix epoch timestamp (assumed to be seconds and UTC):
let unix_time = 1231006505;
let intermediate_timestamp = PoSQLTimestamp::to_timestamp(unix_time).unwrap();
assert_eq!(intermediate_timestamp.timezone(), PoSQLTimeZone::Utc);
Trait Implementations§
source§impl Clone for PoSQLTimestamp
impl Clone for PoSQLTimestamp
source§fn clone(&self) -> PoSQLTimestamp
fn clone(&self) -> PoSQLTimestamp
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for PoSQLTimestamp
impl Debug for PoSQLTimestamp
source§impl<'de> Deserialize<'de> for PoSQLTimestamp
impl<'de> Deserialize<'de> for PoSQLTimestamp
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>,
Deserialize this value from the given Serde deserializer. Read more
source§impl From<PoSQLTimestamp> for Literal
impl From<PoSQLTimestamp> for Literal
source§fn from(time: PoSQLTimestamp) -> Self
fn from(time: PoSQLTimestamp) -> Self
Converts to this type from the input type.
source§impl Hash for PoSQLTimestamp
impl Hash for PoSQLTimestamp
source§impl PartialEq for PoSQLTimestamp
impl PartialEq for PoSQLTimestamp
source§impl Serialize for PoSQLTimestamp
impl Serialize for PoSQLTimestamp
impl Eq for PoSQLTimestamp
impl StructuralPartialEq for PoSQLTimestamp
Auto Trait Implementations§
impl Freeze for PoSQLTimestamp
impl RefUnwindSafe for PoSQLTimestamp
impl Send for PoSQLTimestamp
impl Sync for PoSQLTimestamp
impl Unpin for PoSQLTimestamp
impl UnwindSafe for PoSQLTimestamp
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
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)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
Compare self to
key
and return true
if they are equal.