From 26c7eb90d3afc9e4e81b15365ed1c5f09b01fb59 Mon Sep 17 00:00:00 2001 From: mhov Date: Mon, 15 Aug 2022 13:02:41 -0700 Subject: [PATCH] Date::new(..) re-added --- pgx-tests/src/tests/datetime_tests.rs | 4 ++-- pgx/src/datum/date.rs | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pgx-tests/src/tests/datetime_tests.rs b/pgx-tests/src/tests/datetime_tests.rs index b506f3940b..cb82156bff 100644 --- a/pgx-tests/src/tests/datetime_tests.rs +++ b/pgx-tests/src/tests/datetime_tests.rs @@ -19,7 +19,7 @@ fn accept_date(d: Date) -> Date { #[pg_extern] fn accept_date_round_trip(d: Date) -> Date { match d.try_get_date() { - Ok(date) => Date::from_date(date), + Ok(date) => Date::new(date), Err(pg_epoch_days) => Date::from_pg_epoch_days(pg_epoch_days), } } @@ -136,7 +136,7 @@ mod tests { #[pg_test] fn test_date_serialization() { - let date = Date::from_date( + let date = Date::new( time::Date::from_calendar_date(2020, time::Month::try_from(4).unwrap(), 07).unwrap(), ); let json = json!({ "date test": date }); diff --git a/pgx/src/datum/date.rs b/pgx/src/datum/date.rs index 8b038a5446..0f784435f4 100644 --- a/pgx/src/datum/date.rs +++ b/pgx/src/datum/date.rs @@ -47,6 +47,11 @@ impl Date { pub const NEG_INFINITY: Self = Date(i32::MIN); pub const INFINITY: Self = Date(i32::MAX); + #[inline] + pub fn new(date: time::Date) -> Date { + Self::from_date(date) + } + #[inline] pub fn from_date(date: time::Date) -> Date { Self::from_pg_epoch_days(date.to_julian_day() - pg_sys::POSTGRES_EPOCH_JDATE as i32)