Skip to content

Commit

Permalink
post rebaseline fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mhov committed Oct 2, 2022
1 parent d52e193 commit 176cdb9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions pgx-tests/src/tests/datetime_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 5 additions & 4 deletions pgx/src/datum/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -61,7 +62,7 @@ impl Interval {
impl TryFrom<pg_sys::Datum> for Interval {
type Error = &'static str;
fn try_from(d: pg_sys::Datum) -> Result<Self, Self::Error> {
Ok(Interval(unsafe { *d.ptr_cast() }))
Ok(Interval(unsafe { *d.cast_mut_ptr::<pg_sys::Interval>() }))
}
}

Expand Down Expand Up @@ -118,8 +119,8 @@ impl TryFrom<Duration> for Interval {
impl From<Interval> 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);

Expand Down
13 changes: 6 additions & 7 deletions pgx/src/datum/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion pgx/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 176cdb9

Please sign in to comment.