Skip to content

Commit

Permalink
Date::new(..) re-added
Browse files Browse the repository at this point in the history
  • Loading branch information
mhov committed Aug 15, 2022
1 parent 0140121 commit 26c7eb9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pgx-tests/src/tests/datetime_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
Expand Down Expand Up @@ -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 });
Expand Down
5 changes: 5 additions & 0 deletions pgx/src/datum/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 26c7eb9

Please sign in to comment.