Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes wrong value for microsecs in a day #1849

Conversation

aykut-bozkurt
Copy link
Contributor

@aykut-bozkurt aykut-bozkurt commented Sep 10, 2024

MICROSECONDS_PER_DAY constant at time_with_timezone.rs misses 3 additional zeros for microseconds part.

That breaks conversion from (pg_sys::TimeADT, i32) to TimeWithTimeZone.

Fixes #1850

@@ -24,7 +24,10 @@ use std::panic::{RefUnwindSafe, UnwindSafe};
#[derive(Debug, Copy, Clone)]
#[repr(transparent)]
pub struct TimeWithTimeZone(pg_sys::TimeTzADT);
const MICROSECONDS_PER_DAY: pg_sys::TimeADT = 86_400_000;

// 86_400_000_000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! Could you mention that it comes from the USECS_PER_DAY constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, let's reuse that const across datetime module.

@eeeebbbbrrrr
Copy link
Contributor

Thanks @aykut-bozkurt. Could you add a test for this in the pgrx-tests crate? I believe there’s a module for date/time tests already.

@@ -24,6 +24,9 @@ mod ops;

pub use ctor::*;

pub const USECS_PER_SEC: i64 = 1_000_000;
pub const USECS_PER_DAY: i64 = pg_sys::SECS_PER_DAY as i64 * USECS_PER_SEC;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eeeebbbbrrrr, why does pg_sys has SECS_PER_DAY generated but not USECS_PER_SEC?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm. Probably b/c of how it's defined in timestamp.h:

#define USECS_PER_SEC	INT64CONST(1000000)

Kinda doubt bindgen can see through even that simple of a #define.

@workingjubilee
Copy link
Member

I was very tired that week.

@workingjubilee workingjubilee merged commit 5eadffb into pgcentralfoundation:develop Sep 11, 2024
14 checks passed
@aykut-bozkurt aykut-bozkurt deleted the aykutbozkurt/fix-timetz-conversion branch September 11, 2024 09:27
daamien pushed a commit to daamien/pgrx that referenced this pull request Sep 12, 2024
`MICROSECONDS_PER_DAY` constant at `time_with_timezone.rs` misses 3
additional zeros for microseconds part.

That breaks conversion from `(pg_sys::TimeADT, i32)` to
`TimeWithTimeZone`.

Fixes pgcentralfoundation#1850
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Conversion from TimeTzADT to TimeWithTimeZone is broken
4 participants