Skip to content

Bug in as.ITime.POSIXct #4085

@arunsrinivasan

Description

@arunsrinivasan

I haven't tested on devel but looking at as.ITime.POSIXct, it's identical to the one I've on my system.

require(data.table) # v1.12.2, Rv 3.6.1
Sys.timezone()
# [1] "America/New_York"
x <- Sys.time()
x
# [1] "2019-12-02 12:24:41 EST"
as.ITime(x)
# [1] "17:24:41"

This is incorrect because tz is assumed to be UTC if attr(x, 'tzone') returns NULL which is the case for Sys.time().

> data.table:::as.ITime.POSIXct
function (x, tz = attr(x, "tzone"), ...) 
{
    if (is.null(tz)) 
        tz = "UTC"
    if (tz %chin% c("UTC", "GMT")) 
        as.ITime(unclass(x), ...)
    else as.ITime(as.POSIXlt(x, tz = tz, ...), ...)
}

Why we need tz info to extract HH:MM:SS from a timestamp if I already provide a POSIXct object?

I upgraded from 1.10.4-3 which seems to not have this POSIXct method and delegates to .default, which handles it with as.ITime(as.POSIXlt(x, ...)). Looking at the POSIXct method, it seems similar to old default but with a special case for GMT/UTC. Why so?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions