Bug 17221 - strftime sometimes reports microseconds incorrectly
Summary: strftime sometimes reports microseconds incorrectly
Status: UNCONFIRMED
Alias: None
Product: R
Classification: Unclassified
Component: Language (show other bugs)
Version: R 3.3.*
Hardware: Other Linux
: P5 enhancement
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2017-02-09 21:06 UTC by Frederick Eaton
Modified: 2017-02-09 21:06 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 Frederick Eaton 2017-02-09 21:06:48 UTC
t=as.POSIXlt("1970-01-01 00:00")
t$sec =  4.036236
t
## [1] "1970-01-01 00:00:04 PST"
strftime(t,"%OS6")
## [1] "04.036235"
sprintf("%09.6f",t$sec)
## [1] "04.036236"

I haven't looked at the code which I believe is in the internal function "format.POSIXlt". Perhaps there is a problem with using 'floor' rather than 'round' to convert between numeric types?

t$sec-4
## [1] 0.036236
(t$sec-4)*1e6
## [1] 36236
as.integer((t$sec-4)*1e6)
## [1] 36235
round((t$sec-4)*1e6)
## [1] 36236