Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

floor sub-day precision date before casting to int #981

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ double RDoubleType::Convert(double val) {
}

date_t RDateType::Convert(double val) {
return date_t((int32_t)val);
return date_t((int32_t) std::floor(val));
}

timestamp_t RTimestampType::Convert(double val) {
Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-date.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


test_that("Conversion of sub-dates prior Posix origin is correct", {
con <- dbConnect(duckdb())
on.exit(dbDisconnect(con, shutdown = TRUE))

df <- data.frame(
d = as.Date(c(-1.1, -0.1, 0, 0.1, 1.1), origin = "1970-01-01")
)

duckdb_register(con, "df", df)

res <- sql("from df", con)

expect_identical(
as.character(df$d),
as.character(res$d)
)
})

Loading