Bug 16241 - Incorrect result when combining POSIXct and POSIXlt objects in one call to c.POSIXct
Summary: Incorrect result when combining POSIXct and POSIXlt objects in one call to c....
Status: NEW
Alias: None
Product: R
Classification: Unclassified
Component: Misc (show other bugs)
Version: R 3.1.2
Hardware: All All
: P5 minor
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2015-03-07 20:38 UTC by Marek Gagolewski
Modified: 2015-03-07 20:38 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marek Gagolewski 2015-03-07 20:38:34 UTC
The following call:

c(as.POSIXct(Sys.time()), as.POSIXlt(Sys.time()))

returns:

                                                sec                       min                      hour                      mday 
"2015-03-07 21:28:58 CET" "1970-01-01 01:00:58 CET" "1970-01-01 01:00:28 CET" "1970-01-01 01:00:21 CET" "1970-01-01 01:00:07 CET" 
                      mon                      year                      wday                      yday                     isdst 
"1970-01-01 01:00:02 CET" "1970-01-01 01:01:55 CET" "1970-01-01 01:00:06 CET" "1970-01-01 01:01:05 CET" "1970-01-01 01:00:00 CET" 
                     zone                    gmtoff 
                       NA "1970-01-01 02:00:00 CET" 

whereas one might expect a result like:

[1] "2015-03-07 21:30:16 CET" "2015-03-07 21:30:16 CET"

possible fix: redefine base::c.POSIXct like below:

c.POSIXct <- function(..., recursive=FALSE)
   .POSIXct(c(unlist(lapply(list(...), function(x) unclass(as.POSIXct(x))))))

By the way, the following call is O.K.:

> c.POSIXlt(as.POSIXlt(Sys.time()), as.POSIXct(Sys.time()))
[1] "2015-03-07 21:35:13 CET" "2015-03-07 21:35:13 CET"



> version
               _                           
platform       x86_64-redhat-linux-gnu     
arch           x86_64                      
os             linux-gnu                   
system         x86_64, linux-gnu           
status                                     
major          3                           
minor          1.2                         
year           2014                        
month          10                          
day            31                          
svn rev        66913                       
language       R                           
version.string R version 3.1.2 (2014-10-31)
nickname       Pumpkin Helmet