From 9888866e2dabb1a096f77f0411bc5e4ec33d3f5b Mon Sep 17 00:00:00 2001 From: chiricom Date: Mon, 27 Jul 2026 16:28:12 +0000 Subject: [PATCH] always copy_names() in as.IDate for POSIXct --- NEWS.md | 2 +- R/IDateTime.R | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 5f3276556d..564649f00b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -68,7 +68,7 @@ 14. Subtracting an `IDate` from a `Date` is fast again by avoiding unnecessary conversion to `POSIXlt`/`POSIXct`, [#7825](https://github.com/Rdatatable/data.table/issues/7825). Thanks @gilesheywood for the report and @ben-schwen for the fix. -15. `as.IDate()` and `as.ITime()` now preserve names, matching base `as.Date()` behavior, [#7252](https://github.com/Rdatatable/data.table/issues/7252). Thanks @DavisVaughan for the report and @venom1204 for the PR. +15. `as.IDate()` and `as.ITime()` now preserve names, matching base `as.Date()` behavior, [#7252](https://github.com/Rdatatable/data.table/issues/7252). Thanks @DavisVaughan for the report, @venom1204 for the PR, and @MichaelChirico for patching the fix back to old versions of R. 16. `copy()` is now more consistent about reallocating nested `data.table`s, [#7456](https://github.com/Rdatatable/data.table/issues/7456). The resulting list is now only overwritten when necessary, list columns inside data.tables are searched recursively, and their attributes are walked in search of data.tables to reallocate as well. Thanks to @be-marc for the report, @david-cortes for additional information, and @aitap for the fix. diff --git a/R/IDateTime.R b/R/IDateTime.R index 82b9e53800..6e99f2722a 100644 --- a/R/IDateTime.R +++ b/R/IDateTime.R @@ -47,10 +47,10 @@ as.IDate.POSIXct = function(x, tz = attr(x, "tzone", exact=TRUE), ...) { if (is_utc(tz)) { ans = as.integer(as.numeric(x) %/% 86400L) # %/% returns a new object, so setattr() is safe setattr(ans, "class", c("IDate", "Date")) - copy_names(ans, names(x)) } else { - as.IDate(as.Date(x, tz = tz %||% '', ...)) + ans = as.IDate(as.Date(x, tz = tz %||% '', ...)) } + copy_names(ans, names(x)) } as.IDate.IDate = function(x, ...) x