Skip to content

AVRO-4269: [Java] Fix timestamp-nanos conversion before epoch#3813

Open
emarussoo wants to merge 1 commit into
apache:mainfrom
emarussoo:AVRO-4269-fix-timestamp-nanos-before-epoch
Open

AVRO-4269: [Java] Fix timestamp-nanos conversion before epoch#3813
emarussoo wants to merge 1 commit into
apache:mainfrom
emarussoo:AVRO-4269-fix-timestamp-nanos-before-epoch

Conversation

@emarussoo

Copy link
Copy Markdown

What is the purpose of the change

Fixes TimestampNanosConversion.toLong for Instant values before the Unix epoch with a positive nanosecond component.
The affected code path handles cases where seconds < 0 and nanos > 0. In that branch, the implementation needs to adjust the positive nanosecond component relative to the previous epoch second.
The previous implementation subtracted 1_000_000, which is a microsecond-scale constant. Since this conversion handles the timestamp-nanos logical type, the adjustment must subtract 1_000_000_000L, the number of nanoseconds in one second.
For example, 1969-12-31T23:59:59.999999999Z is one nanosecond before the Unix epoch and should convert to -1L. Before this fix, it converted to 998999999L.
This PR updates the adjustment constant and adds a regression test for the affected pre-epoch nanos case.
Fixes: AVRO-4269

Verifying this change

This change adds a regression test for timestamp-nanos conversion before the epoch.

This change added tests and can be verified as follows:

  • mvn -Dtest=TestTimeConversions#timestampNanosConversionBeforeEpochWithPositiveNanos test
  • mvn -Dtest=TestTimeConversions test

Documentation

  • Does this pull request introduce a new feature? no
  • If yes, how is the feature documented? not applicable

@github-actions github-actions Bot added the Java Pull Requests for Java binding label Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Java Pull Requests for Java binding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant