Skip to content

fix: Round bound times to the nearest microsecond - #610

Merged
krlmlr merged 2 commits into
mainfrom
claude/bind-microseconds
Nov 29, 2026
Merged

krlmlr merged 2 commits into
mainfrom
claude/bind-microseconds

Conversation

@krlmlr

@krlmlr krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member

Closes #605.

Before this change, set_time_buffer() truncated the fractional seconds of bound POSIXct and hms values. Because of floating-point representation, .000001 was bound as .000000.

Change

  • Each POSIXct or hms value is rounded to a whole number of microseconds with llround(val * 1e6) before it is split into its parts. set_time_buffer() takes that 64-bit count and uses integer arithmetic only.
  • For DATETIME, the date comes from floor division of the count. A value that rounds up therefore carries into the next second, minute, hour and day, also for times before 1970.
  • Date binding is unchanged, since it uses floor() on days. difftime values are converted to hms in R first, so they take the fixed path.
  • The read side in src/MariaRow.cpp already keeps microseconds, and is not touched.

Tests

tests/testthat/test-bind-microseconds.R (new) covers dbBind() into DATETIME(6) and TIME(6), and a dbWriteTable() round trip. The cases are 1 µs and 999999 µs, a rollover to the next midnight, values before 1970, carries in hms, and negative hms values. 4 of its 6 expectations fail without the fix. Local run against MariaDB 10.11 with NOT_CRAN=true: the whole suite had 0 failures and the one test-timezone.R error ("US/Alaska" unknown to CCTZ in this container), which also happens on main. MySQL was not tested: there is no server in this container, and CI's MySQL entries currently run MariaDB (#592).

Found along the way

Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ


Generated by Claude Code

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Accepted limitations

The clean review found nothing above Low.


Generated by Claude Code

@krlmlr
krlmlr marked this pull request as ready for review November 29, 2026 12:06
@krlmlr
krlmlr added this pull request to stack #617 November 29, 2026 12:13
@krlmlr
krlmlr merged commit a7ee9af into main Nov 29, 2026
1 check passed
@krlmlr
krlmlr deleted the claude/bind-microseconds branch November 29, 2026 13:56
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.

Binding POSIXct or hms values can lose a microsecond

2 participants