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

Split timestamp_s_to_datetime to date and time to avoid unnecessary computation #6755

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jayzhan211
Copy link
Contributor

@jayzhan211 jayzhan211 commented Nov 19, 2024

Which issue does this PR close?

Closes #6746 .

Rationale for this change

What changes are included in this PR?

Are there any user-facing changes?

I think we don't need to change chrono crate

Signed-off-by: jayzhan211 <[email protected]>
Signed-off-by: jayzhan211 <[email protected]>
@github-actions github-actions bot added the arrow Changes to the arrow crate label Nov 19, 2024
/// except for 1700, 1800 and 1900 -3 +
/// --------
/// 719163
pub const UNIX_EPOCH_DAY: i64 = 719_163;
Copy link
Contributor

Choose a reason for hiding this comment

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

this looks to be identical to the EPOCH_DAYS_FROM_CE const above, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems that EPOCH_DAYS_FROM_CE is actually not used, remove it. To keep the variable name consistent to chrono

/// Similar to timestamp_s_to_datetime but only compute `date`
#[inline]
pub fn timestamp_s_to_date(secs: i64) -> Option<NaiveDateTime> {
let days = secs.div_euclid(86_400) + UNIX_EPOCH_DAY;
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we're ignoring leap seconds here?

/// Similar to timestamp_s_to_datetime but only compute `time`
#[inline]
pub fn timestamp_s_to_time(secs: i64) -> Option<NaiveDateTime> {
let secs = secs.rem_euclid(86_400);
Copy link
Contributor

Choose a reason for hiding this comment

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

and ignoring leap seconds here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean leap second? The code is copied from chrono I prefer to keep than consistent if possible. If the computation is not expected we should fix it in chrono

Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose that depends on whether the place where this came from is supposed to respect leap seconds, etc or not. It's not technically correct when using UTC, see https://en.wikipedia.org/wiki/Leap_second for a list of leap seconds since unix epoch. It's also not going to be far off either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's support it when chrono did so.

Signed-off-by: Jay Zhan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid from_num_days_from_ce_opt calls in timestamp_s_to_datetime if we don't need
2 participants