Struct 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

Source

pub fn timestamp(&self) -> DateTime<Utc>

Returns the combined date and time with time zone.

Source

pub fn timeunit(&self) -> PoSQLTimeUnit

Returns the PoSQLTimeUnit for this timestamp

Source

pub fn timezone(&self) -> PoSQLTimeZone

Returns the PoSQLTimeZone for this timestamp

Source

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:

  1. 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 appropriate PoSQLTimeZone.
  2. Timezone Parsing and Conversion:

    • The from_offset method is used to determine whether the timezone should be represented as Utc or FixedOffset. This function simplifies the decision based on the offset value.
§Errors

This function returns a PoSQLTimestampError in the following cases:

  • Parsing Error: Returns PoSQLTimestampError::ParsingError if the input string does not conform to the RFC 3339 format or if the timestamp cannot be parsed due to invalid formatting. This error includes the original parsing error message for further details.
§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::new(10800)); // 3 hours in seconds
Source

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

This function returns a PoSQLTimestampError in the following cases:

  • Ambiguous Time: Returns PoSQLTimestampError::Ambiguous if the provided epoch time corresponds to a time that is ambiguous (e.g., during a daylight saving time change where the local time could correspond to two different UTC times).

  • Non-Existent Local Time: Returns PoSQLTimestampError::LocalTimeDoesNotExist if the provided epoch time corresponds to a time that does not exist in the local time zone (e.g., during a daylight saving time change where a certain local time is skipped).

§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

Source§

fn clone(&self) -> PoSQLTimestamp

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PoSQLTimestamp

Source§

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

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

impl<'de> Deserialize<'de> for PoSQLTimestamp

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 From<PoSQLTimestamp> for Literal

Source§

fn from(time: PoSQLTimestamp) -> Self

Converts to this type from the input type.
Source§

impl Hash for PoSQLTimestamp

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 PoSQLTimestamp

Source§

fn eq(&self, other: &PoSQLTimestamp) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Serialize for PoSQLTimestamp

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 Eq for PoSQLTimestamp

Source§

impl StructuralPartialEq for PoSQLTimestamp

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> 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, 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,