Repository navigation
fix: Fix timezone conversion for invalid timestamps with tz_out_convert = "force" - #1474
Merged
Merged
Conversation
… as.POSIXct Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Copilot
AI
changed the title
[WIP]
Fix tz_out_convert=force timezone conversion losing time component for invalid timestamps
Sep 7, 2025
tz_out_convert = force sets all times to midnight in TIMESTAMPS whenever any supplied datetimes are invalidtz_out_convert = "force"
krlmlr
marked this pull request as ready for review
September 7, 2025 13:19
krlmlr
enabled auto-merge
September 7, 2025 13:20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When using
tz_out_convert = "force"with DuckDB R package, if any returned timestamps are invalid (e.g., during DST transitions), then all times get converted incorrectly, with some losing their time component and becoming date-only values.The issue occurs in the
tz_force_one()function inR/Result.Rwhich callsas.POSIXct(ct, tz = timezone)without specifying aformatparameter. Whenas.POSIXctdoesn't have an explicit format, it tries various formats fromtryFormatsuntil finding one that returns no NA values. For invalid timestamps during DST transitions, this can result in using the"%Y-%m-%d"format, which only captures dates and loses time information.Example of the issue:
This fix adds the explicit
format = "%Y-%m-%d %H:%M:%OS"parameter to theas.POSIXct()call intz_force_one(), preventing it from trying multiple formats and ensuring consistent behavior. Valid timestamps retain their full time information, while invalid timestamps during DST transitions will be handled appropriately rather than causing time loss for all timestamps.The fix also includes a test case that validates the expected behavior for DST transition scenarios.
Fixes #1470.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
cran.r-project.org/usr/lib/R/bin/exec/R --vanilla -e ~n~install.packages(c('testthat',~+~'DBI',~+~'withr'),~+~repos='REDACTED',~+~quiet=TRUE)~n~(dns block)esm.ubuntu.com/usr/lib/apt/methods/https(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.