Skip to content
Prev 47773 / 63424 Next

How to convert time_t to R date object

On 17/03/2014 11:39, Dirk Eddelbuettel wrote:
But note that time_t is not 'int' on many modern systems: almost all 
64-bit ones and on some 32-bit ones.

I guess this is actually meant to be a date-time object, hence class 
POSIXct.  Class POSIXct is based on doubles, so return a double and add 
the classes in the R wrapper.  If you want class Date, divide by 86400 
and return an integer.

That does assume that the system is POSIX-compliant and so ignores leap 
seconds.   I have not encountered one that is not for many years, but 
allegedly there are locales which do count leap seconds on some 
Unix-alikes.  C code to adjust that is in src/main/datetime.c in the R 
sources.