From 176cdb969166e3196b889b38f4597c117742e5bb Mon Sep 17 00:00:00 2001 From: mhov Date: Sat, 1 Oct 2022 21:47:46 -0700 Subject: [PATCH] post rebaseline fixes --- pgx-tests/src/tests/datetime_tests.rs | 1 + pgx/src/datum/interval.rs | 9 +++++---- pgx/src/datum/time.rs | 13 ++++++------- pgx/src/prelude.rs | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/pgx-tests/src/tests/datetime_tests.rs b/pgx-tests/src/tests/datetime_tests.rs index 1d007e2228..2fbf98f31d 100644 --- a/pgx-tests/src/tests/datetime_tests.rs +++ b/pgx-tests/src/tests/datetime_tests.rs @@ -530,6 +530,7 @@ mod tests { #[pg_test] fn test_duration_to_interval_err() { + use pgx::IntervalConversionError; // normal limit of i32::MAX months let duration = time::Duration::days(pg_sys::DAYS_PER_MONTH as i64 * i32::MAX as i64); diff --git a/pgx/src/datum/interval.rs b/pgx/src/datum/interval.rs index 64f465a9e6..d54616b776 100644 --- a/pgx/src/datum/interval.rs +++ b/pgx/src/datum/interval.rs @@ -9,7 +9,8 @@ Use of this source code is governed by the MIT license that can be found in the use std::ops::{Mul, Sub}; -use crate::{direct_function_call, pg_sys, FromDatum, IntoDatum, USECS_PER_SEC}; +use crate::datum::time::USECS_PER_SEC; +use crate::{direct_function_call, pg_sys, FromDatum, IntoDatum}; use pg_sys::{DAYS_PER_MONTH, SECS_PER_DAY}; use pgx_utils::sql_entity_graph::metadata::{ ArgumentError, Returns, ReturnsError, SqlMapping, SqlTranslatable, @@ -61,7 +62,7 @@ impl Interval { impl TryFrom for Interval { type Error = &'static str; fn try_from(d: pg_sys::Datum) -> Result { - Ok(Interval(unsafe { *d.ptr_cast() })) + Ok(Interval(unsafe { *d.cast_mut_ptr::() })) } } @@ -118,8 +119,8 @@ impl TryFrom for Interval { impl From for Duration { fn from(interval: Interval) -> Duration { let interval = interval.0; // internal interval - let sec = interval.time / USECS_PER_SEC; - let fsec = ((interval.time - (sec * USECS_PER_SEC)) * 1000) as i32; // convert usec to nsec + let sec = interval.time / USECS_PER_SEC as i64; + let fsec = ((interval.time - (sec * USECS_PER_SEC as i64)) * 1000) as i32; // convert usec to nsec let mut duration = Duration::new(sec, fsec); diff --git a/pgx/src/datum/time.rs b/pgx/src/datum/time.rs index 20f32c5e0e..a2900b325f 100644 --- a/pgx/src/datum/time.rs +++ b/pgx/src/datum/time.rs @@ -14,13 +14,12 @@ use pgx_utils::sql_entity_graph::metadata::{ }; use time::format_description::FormatItem; -pub(crate) const USECS_PER_HOUR: i64 = 3_600_000_000; -pub(crate) const USECS_PER_MINUTE: i64 = 60_000_000; -pub(crate) const USECS_PER_SEC: i64 = 1_000_000; -#[allow(dead_code)] -pub(crate) const USECS_PER_DAY: i64 = pg_sys::SECS_PER_DAY as i64 * USECS_PER_SEC; -pub(crate) const MINS_PER_HOUR: i64 = 60; -pub(crate) const SEC_PER_MIN: i64 = 60; +const MINS_PER_HOUR: u64 = 60; +const SEC_PER_MIN: u64 = 60; +pub(crate) const USECS_PER_SEC: u64 = 1_000_000; +pub(crate) const USECS_PER_MINUTE: u64 = USECS_PER_SEC * SEC_PER_MIN; +pub(crate) const USECS_PER_HOUR: u64 = USECS_PER_MINUTE * MINS_PER_HOUR; +pub(crate) const USECS_PER_DAY: u64 = USECS_PER_HOUR * 24; #[derive(Debug, Clone, PartialEq)] #[repr(transparent)] diff --git a/pgx/src/prelude.rs b/pgx/src/prelude.rs index 7b2bb1bcb9..874d23d226 100644 --- a/pgx/src/prelude.rs +++ b/pgx/src/prelude.rs @@ -17,7 +17,7 @@ pub use crate::pgbox::PgBox; // These could be factored into a temporal type module that could be easily imported for code which works with them. // However, reexporting them seems fine for now. -pub use crate::datum::{Date, Time, TimeWithTimeZone, Timestamp, TimestampWithTimeZone}; +pub use crate::datum::{Date, Interval, Time, TimeWithTimeZone, Timestamp, TimestampWithTimeZone}; pub use crate::pg_sys::PgBuiltInOids;