Skip to content
Merged
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: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@

36. `DT[id==1, DT2[.SD, on="id"]]` (i.e. joining from `.SD` in `j`) could incorrectly fail in some cases due to `.SD` being locked, [#1926](https://github.com/Rdatatable/data.table/issues/1926). Thanks @franknarf1 for the report and for diligently tracking use cases for almost 3 years!

37. `as.IDate.POSIXct` returned `NA` for UTC times before Dec 1901 and after Jan 2038, [#3780](https://github.com/Rdatatable/data.table/issues/3780). Thanks @gschett for the report.

#### NOTES

1. `rbindlist`'s `use.names="check"` now emits its message for automatic column names (`"V[0-9]+"`) too, [#3484](https://github.com/Rdatatable/data.table/pull/3484). See news item 5 of v1.12.2 below.
Expand Down
8 changes: 4 additions & 4 deletions R/IDateTime.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ as.IDate.Date = function(x, ...) {
as.IDate.POSIXct = function(x, tz = attr(x, "tzone", exact=TRUE), ...) {
if (is.null(tz)) tz = "UTC"
if (tz %chin% c("UTC", "GMT")) {
(setattr(as.integer(x) %/% 86400L, "class", c("IDate", "Date"))) # %/% returns new object so can use setattr() on it; wrap with () to return visibly
(setattr(as.integer(as.numeric(x) %/% 86400L), "class", c("IDate", "Date"))) # %/% returns new object so can use setattr() on it; wrap with () to return visibly
} else
as.IDate(as.Date(x, tz = tz, ...))
}
Expand Down Expand Up @@ -305,23 +305,23 @@ as.POSIXlt.ITime = function(x, ...) {
second = function(x) {
if (inherits(x, 'POSIXct') && identical(attr(x, 'tzone', exact=TRUE), 'UTC')) {
# if we know the object is in UTC, can calculate the hour much faster
as.integer(x) %% 60L
as.integer(as.numeric(x) %% 60L)
} else {
as.integer(as.POSIXlt(x)$sec)
}
}
minute = function(x) {
if (inherits(x, 'POSIXct') && identical(attr(x, 'tzone', exact=TRUE), 'UTC')) {
# ever-so-slightly faster than x %% 3600L %/% 60L
as.integer(x) %/% 60L %% 60L
as.integer(as.numeric(x) %/% 60L %% 60L)
} else {
as.POSIXlt(x)$min
}
}
hour = function(x) {
if (inherits(x, 'POSIXct') && identical(attr(x, 'tzone', exact=TRUE), 'UTC')) {
# ever-so-slightly faster than x %% 86400L %/% 3600L
as.integer(x) %/% 3600L %% 24L
as.integer(as.numeric(x) %/% 3600L %% 24L)
} else {
as.POSIXlt(x)$hour
}
Expand Down
8 changes: 8 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -15827,6 +15827,14 @@ df1 = data.table(a=1:5, b=c(0, 0, 1, 0, 2))
df2 = data.table(c=c(1, 1, 2, 2, 3), d=c(3, 4, 3, 5, 4))
test(2092.3, copy(df2)[ , s := df1[.SD, on=.(a >= c, a <= d), sum(b), by=.EACHI]$V1],
df2[ , s := c(1, 1, 1, 3, 1)])

# POSIXct overflow to NA before 1901 and after 2038, #3780
date=as.POSIXct("1900-01-01", tz="UTC")
test(2093.1, as.IDate(date), as.IDate(-25567L))
test(2093.2, hour(date), 0L)
test(2093.3, minute(date), 0L)
test(2093.4, second(date), 0L)


###################################
# Add new tests above this line #
Expand Down