Skip to content

Commit

Permalink
Add from impls for pg_sys -> pgx timestamp* (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamessewell authored Mar 29, 2022
1 parent 38fe62a commit 16dc858
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pgx/src/datum/time_stamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ use time::{format_description::FormatItem, PrimitiveDateTime};

#[derive(Debug, Copy, Clone)]
pub struct Timestamp(time::PrimitiveDateTime);

impl From<pg_sys::Timestamp> for Timestamp {
fn from(item: pg_sys::Timestamp) -> Self {
unsafe { Timestamp::from_datum(item as usize, false, pg_sys::TIMESTAMPOID).unwrap() }
}
}

impl FromDatum for Timestamp {
#[inline]
unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, typoid: u32) -> Option<Timestamp> {
Expand Down
7 changes: 7 additions & 0 deletions pgx/src/datum/time_stamp_with_timezone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ use time::{format_description::FormatItem, UtcOffset};
#[derive(Debug, Copy, Clone)]
pub struct TimestampWithTimeZone(time::OffsetDateTime);

impl From<pg_sys::TimestampTz> for TimestampWithTimeZone {
fn from(item: pg_sys::TimestampTz) -> Self {
unsafe { TimestampWithTimeZone::from_datum(item as usize, false, pg_sys::TIMESTAMPTZOID).unwrap() }
}
}


impl FromDatum for TimestampWithTimeZone {
#[inline]
unsafe fn from_datum(
Expand Down

0 comments on commit 16dc858

Please sign in to comment.