Skip to content

fix: round relative time seconds exactly#25994

Open
hiSandog wants to merge 1 commit into
apache:masterfrom
hiSandog:fix/relative-time-rounding-20260611
Open

fix: round relative time seconds exactly#25994
hiSandog wants to merge 1 commit into
apache:masterfrom
hiSandog:fix/relative-time-rounding-20260611

Conversation

@hiSandog

Copy link
Copy Markdown
Contributor

Motivation

RelativeTimeUtil.nsToSeconds currently builds a BigDecimal from a double. For half-up rounding cases such as 1.2345 seconds, the binary double value can be slightly below the decimal half and round down unexpectedly.

Modifications

  • Convert nanoseconds with BigDecimal.valueOf(ns, 9) so the decimal value is exact before rounding.
  • Apply the same fix to both common and cli-utils RelativeTimeUtil implementations.
  • Add coverage for a half-up rounding boundary.

Verifications

  • git diff --check
  • Not run: ./gradlew :pulsar-common:test --tests "org.apache.pulsar.common.util.RelativeTimeUtilTest" -PtestRetryCount=0 (local environment has no Java Runtime)

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.

1 participant