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 @@ -8,6 +8,8 @@

## BUG FIXES

1. A NULL timezone on POSIXct was interpreted by `as.IDate` and `as.ITime` as UTC rather than the session's default timezone (`tz=""`) , [#4085](https://github.com/Rdatatable/data.table/issues/4085).

## NOTES


Expand Down
4 changes: 2 additions & 2 deletions R/IDateTime.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ as.IDate.Date = function(x, ...) {
}

as.IDate.POSIXct = function(x, tz = attr(x, "tzone", exact=TRUE), ...) {
if (is.null(tz)) tz = "UTC"
if (is.null(tz)) tz=''
if (tz %chin% c("UTC", "GMT")) {
(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
Expand Down Expand Up @@ -138,7 +138,7 @@ as.ITime.default = function(x, ...) {
}

as.ITime.POSIXct = function(x, tz = attr(x, "tzone", exact=TRUE), ...) {
if (is.null(tz)) tz = "UTC"
if (is.null(tz)) tz=''
if (tz %chin% c("UTC", "GMT")) as.ITime(unclass(x), ...)
else as.ITime(as.POSIXlt(x, tz = tz, ...), ...)
}
Expand Down
8 changes: 8 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -16392,6 +16392,14 @@ test(2122.2, DT, data.table(V3=5:6))
dt = data.table(SomeNumberA=c(1,1,1),SomeNumberB=c(1,1,1))
test(2123, dt[, .(.N, TotalA=sum(SomeNumberA), TotalB=sum(SomeNumberB)), by=SomeNumberA], data.table(SomeNumberA=1, N=3L, TotalA=1, TotalB=3))

# system timezone is not usually UTC, so as.ITime.POSIXct shouldn't assume so, #4085
oldtz=Sys.getenv('TZ')
Sys.setenv(TZ='Asia/Jakarta') # UTC+7
t0 = as.POSIXct('2019-10-01')
test(2124.1, format(as.ITime(t0)), '00:00:00')
test(2124.2, format(as.IDate(t0)), '2019-10-01')
Sys.setenv(TZ=oldtz)


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