Skip to content

GH-1293: Use floor division when splitting epoch millis into day and time - #1294

Open
AbhishekPathania wants to merge 1 commit into
apache:mainfrom
AbhishekPathania:gh-1293-floor-epoch-day
Open

GH-1293: Use floor division when splitting epoch millis into day and time#1294
AbhishekPathania wants to merge 1 commit into
apache:mainfrom
AbhishekPathania:gh-1293-floor-epoch-day

Conversation

@AbhishekPathania

@AbhishekPathania AbhishekPathania commented Sep 11, 2026

Copy link
Copy Markdown

What's Changed

DateTimeUtils.getTimestampValue(long) used / and % to split epoch milliseconds into an epoch day and a time within that day. These operators round toward zero. For negative values that were not exactly midnight, the existing code fixed the remainder but not the epoch day. The two parts then referred to different days, so the timestamp came back one day late.

For example, -618102000000 ms is 1950-06-01 01:00:00 UTC. The old division produced epoch day -7153, which is 1950-06-02, while the remainder was 01:00. The method returned 1950-06-02 01:00:00.

This affects DATE values before 1970 when ArrowFlightJdbcDateVectorAccessor.getDate(Calendar) applies a non-zero calendar offset. The offset moves the value away from midnight and exposes the division bug.

The method now uses Math.floorDiv for the epoch day and Math.floorMod for the time within the day. This also removes the need for the manual negative-remainder adjustment. Positive values behave as before.

DateTimeUtilsTest now tests 1950-06-01 01:00:00 UTC. The old code returned 1950-06-02 01:00:00 for this input. The test passes with the new floor-based calculation.

Closes #1293.

…y and time

DateTimeUtils.getTimestampValue split epoch millis into an epoch day and a
time-of-day remainder using `/` and `%`, which truncate toward zero. Only the
remainder half compensated for negative input, so for any negative value that
was not an exact multiple of a day the two halves described different days and
the returned timestamp was one day later than the instant given. This is
reachable from ArrowFlightJdbcDateVectorAccessor.getDate(Calendar), where the
calendar offset shifts a day-aligned date value off that alignment, making
every pre-1970 date come back a day late.

Use Math.floorDiv and Math.floorMod for both halves, which keeps the day and
the remainder on the same day and makes the manual negative adjustment
redundant. Positive input is unaffected, since both functions agree with `/`
and `%` there.

Closes apache#1293.
@github-actions

This comment has been minimized.

@AbhishekPathania

Copy link
Copy Markdown
Author

The "Ensure PR format" check is failing only on the missing label step. I tried to add bug-fix when opening the PR, but label changes need write access on the repo (403 for an outside contributor). Could a committer add bug-fix? The title and the issue link both pass.

@lidavidm lidavidm added the bug-fix PRs that fix a big. label Sep 11, 2026
@github-actions github-actions Bot added this to the 20.0.0 milestone Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix PRs that fix a big.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Java][FlightSQL] JDBC driver returns pre-1970 dates one day late when a Calendar is supplied

2 participants