[R] POSIXct bug?
Martin Maechler
maechler at stat.math.ethz.ch
Mon Feb 28 09:08:42 CET 2005
>>>>> "Spencer" == Spencer Graves <spencer.graves at pdf.com>
>>>>> on Sun, 27 Feb 2005 07:15:44 -0800 writes:
Spencer> Hi, Gabor: Of course: time zone vs. GMT.
Spencer> Next question: Might a simple example that
Spencer> illustrates this be added to the help file for
Spencer> "as.POSIXct", and if yes, what should be done to
Spencer> make that happen?
send such a simple example {few lines of R code + comments ("# ...")}
to R-devel (or to an R-core member you know who would take it up).
Martin
Spencer> Gabor Grothendieck wrote:
>> Spencer Graves <spencer.graves <at> pdf.com> writes:
>>
>> :
>> : In R 2.0.1 under Windows 2000, at least in some cases, as.POSIXct
>> : adds one to the date:
>> :
>> : > March1.1959.POSIXct <- as.POSIXct("1959-03-01")
>> : > March1.1959.POSIXlt <- as.POSIXlt("1959-03-01")
>> : >
>> : > (Mar2.59 <- as.Date(March1.1959.POSIXct))
>> : [1] "1959-03-02"
>> : > as.Date(March1.1959.POSIXlt)
>> : [1] "1959-03-01"
>> : >
>> : > as.Date(as.POSIXct(Mar2.59))
>> : [1] "1959-03-02"
>> : > as.Date(as.POSIXct(as.character(Mar2.59)))
>> : [1] "1959-03-03"
>> : > print(POSIX.i <- as.POSIXct("1959-03-01"))
>> : [1] "1959-03-01 Pacific Standard Time"
>> : > for(i in 1:11){
>> : + print(date.i <- as.Date(POSIX.i))
>> : + print(POSIX.i <- as.POSIXct(as.character(date.i)))
>> : + }
>> : [1] "1959-03-02"
>> : [1] "1959-03-02 Pacific Standard Time"
>> : [1] "1959-03-03"
>> : [1] "1959-03-03 Pacific Standard Time"
>> : [1] "1959-03-04"
>> : [1] "1959-03-04 Pacific Standard Time"
>> : [1] "1959-03-05"
>> : [1] "1959-03-05 Pacific Standard Time"
>> : [1] "1959-03-06"
>> : [1] "1959-03-06 Pacific Standard Time"
>> : [1] "1959-03-07"
>> : [1] "1959-03-07 Pacific Standard Time"
>> : [1] "1959-03-08"
>> : [1] "1959-03-08 Pacific Standard Time"
>> : [1] "1959-03-09"
>> : [1] "1959-03-09 Pacific Standard Time"
>> : [1] "1959-03-10"
>> : [1] "1959-03-10 Pacific Standard Time"
>> : [1] "1959-03-11"
>> : [1] "1959-03-11 Pacific Standard Time"
>> : [1] "1959-03-12"
>> : [1] "1959-03-12 Pacific Standard Time"
>> : >
>> : Comments?
>>
>> I am not sure that the code really speaks for itself. What is the bug?
>> Note that as.Date converts dates relative to GMT, not the current time
>> zone. If you want to convert a POSIXct date to a Date date relative
>> to the current timezone you can convert it to character first. RNews 4/1
>> has a table that provides a number of such idioms.
More information about the R-help
mailing list