An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20100903/6837d295/attachment.pl>
Incorrect formatted output after subtracting non-integer seconds from POSIXt origin
3 messages · Daniel Murphy, Simon Urbanek
On Sep 3, 2010, at 7:56 PM, Daniel Murphy wrote:
x<-as.POSIXct("1970-1-1", tz="UTC")-.5
y<-as.POSIXct("1970-1-1", tz="UTC")+.5
x==y
[1] FALSE # of course but x and y "appear" to be the same when formatted, even with extra precision:
format(x, format="%Y-%m-%d %H:%M:%OS2")
[1] "1970-01-01 00:00:00.50"
format(y, format="%Y-%m-%d %H:%M:%OS2")
[1] "1970-01-01 00:00:00.50" Formatted output is fine for integral difference points ...
x<-as.POSIXct("1970-1-1", tz="UTC")-1
y<-as.POSIXct("1970-1-1", tz="UTC")+1
format(x, format="%Y-%m-%d %H:%M:%OS2")
[1] "1969-12-31 23:59:59.00"
format(y, format="%Y-%m-%d %H:%M:%OS2")
[1] "1970-01-01 00:00:01.00" ... but seems to be a second "off" for non-integers:
format(as.POSIXct("1970-1-1", tz="UTC")-1.5, format="%Y-%m-%d %H:%M:%OS2")
[1] "1969-12-31 23:59:59.50" # a second later than expected
format(as.POSIXct("1970-1-1", tz="UTC")-86400, format="%Y-%m-%d
%H:%M:%OS2") [1] "1969-12-31 00:00:00.00" # OK
format(as.POSIXct("1970-1-1", tz="UTC")-86400.5, format="%Y-%m-%d
%H:%M:%OS2") [1] "1969-12-31 00:00:00.50" # why "after" previous time? Bug, or user misunderstanding?
If negative POSIX time is supposed to work then it's a bug in as.POSIXlt(). Now fixed in R-devel (and patched). Cheers, Simon before:
str(unclass(as.POSIXlt(as.POSIXct("1970-1-1", tz="UTC")-0.2)))
List of 9 $ sec : num 0.8 $ min : int 0 $ hour : int 0 $ mday : int 1 $ mon : int 0 $ year : int 70 $ wday : int 4 $ yday : int 0 $ isdst: int 0 - attr(*, "tzone")= chr "UTC" R-devel:
str(unclass(as.POSIXlt(as.POSIXct("1970-1-1", tz="UTC")-0.2)))
List of 9 $ sec : num 59.8 $ min : int 59 $ hour : int 23 $ mday : int 31 $ mon : int 11 $ year : int 69 $ wday : int 3 $ yday : int 364 $ isdst: int 0 - attr(*, "tzone")= chr "UTC"
"R version 2.11.1 (2010-05-31)" on Windows Thanks. Dan Murphy [[alternative HTML version deleted]]
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20100903/191fc31a/attachment.pl>