[Rd] Incorrect formatted output after subtracting non-integer seconds from POSIXt origin
Simon Urbanek
simon.urbanek at r-project.org
Sat Sep 4 04:44:46 CEST 2010
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
>
>
More information about the R-devel
mailing list