[R] timeBasedSeq stumbles over the year 2038 (xts package)

Joshua Ulrich josh.m.ulrich at gmail.com
Thu Aug 2 02:41:04 CEST 2012


This isn't the year 2038 problem and workaround #2 won't help because
R uses the tm structure, not time_t.

Here's a non-xts example of the issue, which seems to be in as.POSIXct.POSIXlt:
x <- "2038-12-31-23-59-59.99999"
(y <- strptime(x, "%Y-%m-%d-%H-%M-%OS"))
unclass(y)
(z <- as.POSIXct(y))

I thought this may have something to do with timezones / daylight
saving time, since ?DateTimeClasses says that dates up to 2037 are
covered; but setting tz="GMT" doesn't help.
(y1 <- strptime(x, "%Y-%m-%d-%H-%M-%OS", tz="GMT"))
unclass(y1)
(z1 <- as.POSIXct(y1, tz="GMT"))

do_asPOSIXct is at line 733 of main/datetime.c, for anyone interested
in digging further.

Best,
--
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com


On Wed, Aug 1, 2012 at 6:10 PM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:
> http://en.wikipedia.org/wiki/Year_2038_problem
>
> Workaround 1: Avoid collecting data in the future and processing it in the present.
>
> Workaround 2: Use a 64-bit build of R, as appropriate for such future data sets.
> ---------------------------------------------------------------------------
> Jeff Newmiller                        The     .....       .....  Go Live...
> DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
>                                       Live:   OO#.. Dead: OO#..  Playing
> Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
> /Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
> ---------------------------------------------------------------------------
> Sent from my phone. Please excuse my brevity.
>
> Marcus Kriele <mkriele at mac.com> wrote:
>
>>I have the following problem:
>>
>>As expected I obtain
>> timeBasedSeq( 2037/2037)
>>[1] "2037-01-01"
>>>
>>However if I do the same for 2038 I get
>>timeBasedSeq( 2038/2038)
>>[1] "2038-01-01" "2039-01-01"
>>
>>I get the same strange result if I use later years or any interval that
>>contains 2038:
>>timeBasedSeq( 2037/2039)
>>[1] "2037-01-01" "2038-01-01" "2039-01-01" "2040-01-01"
>>>
>>
>>Am I doing anything wrong?  I am using R2.15.1 und xts 0.8.6 on a mac.
>>
>>Many thanks,  Marcus
>>
>>
>>       [[alternative HTML version deleted]]
>>
>>______________________________________________
>>R-help at r-project.org mailing list
>>https://stat.ethz.ch/mailman/listinfo/r-help
>>PLEASE do read the posting guide
>>http://www.R-project.org/posting-guide.html
>>and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list