Skip to content

as.IDate() : floor fractional dates, #7952 - #7966

Open
simplymayank wants to merge 6 commits into
Rdatatable:masterfrom
simplymayank:7952-fix-fractional-dates
Open

simplymayank wants to merge 6 commits into
Rdatatable:masterfrom
simplymayank:7952-fix-fractional-dates

Conversation

@simplymayank

Copy link
Copy Markdown

Closes #7952

as.IDate() truncated fractional Date and numeric inputs toward zero, so negative fractions (e.g. -0.5) gave the wrong day. This now floors instead.

The approach follows the fix suggested by @ben-schwen in @ben-schwen's comment.

Changes

  • Add floor_to_int() to handle fractional Date and numeric inputs.
  • Add tests for fractional Date and numeric inputs around the Unix epoch.
  • Add NEWS entry.

Testing

  • I checked that the new negative-value tests fail on current master and pass with this change.
  • test.data.table() passes and R CMD check completes with no errors, warnings, or notes

Performance

Used bench::mark() for floor_to_int() against the previous as.integer() on 1 million values:

  • Random double values: median 2.4 ms -> 11.6 ms.
  • Integer-valued doubles: median 2.34 ms -> 6.68 ms.
  • Integer vectors: 400 ns -> 4 µs.

This change ensures correct date conversion for negative fractional values, with some additional processing time for double inputs.

This branch has not been deployed

No deployments
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.

Document as.IDate() behaviour with fractional dates

1 participant