From mcintosh at research.telcordia.com  Thu Oct 28 05:09:42 2004
From: mcintosh at research.telcordia.com (mcintosh@research.telcordia.com)
Date: Thu Oct 28 05:09:47 2004
Subject: [Rd] POSIX time anomaly (PR#7317)
Message-ID: <20041028030942.DC5D411350@slim.kubism.ku.dk>

Full_Name: Allen McIntosh
Version: 2.0.0
OS: RedHat 9.0
Submission from: (NULL) (67.80.175.118)


The POSIX time printing routine gives strange results when asked to print a time
that is exactly midnight:

TZ=CST6CDT R -q --no-save
> strptime("10/5/2004 00:00:01 CDT", "%m/%d/%Y %H:%M:%S %Z")
[1] "2004-10-05 00:00:01"
> strptime("10/5/2004 00:00:00 CDT", "%m/%d/%Y %H:%M:%S %Z")
[1] "2004-10-05"
> strptime("10/4/2004 24:00:00 CDT", "%m/%d/%Y %H:%M:%S %Z")
[1] NA 

The first time is OK.  The second is missing the HH:MM:SS.
I'm OK with the last one being NA, just did it to see if that was the way that
the code wanted midnight.

Get the underlying # seconds:

> zz <- as.POSIXct(strptime("10/5/2004 00:00:00 CDT", "%m/%d/%Y %H:%M:%S %Z"))
> attr(zz,"class") <- NULL
> zz
[1] 1096952400
attr(,"tzone")
[1] ""
> 

and (just to see if the problem is glibc or something):
$ cat ct.c
#include <time.h>
#include <stdio.h>
main() {
        time_t z = 1096952400;
        printf("%s\n", ctime(&z));
        return 0;
}
$ gcc -o ct ct.c
$ TZ=CST6CDT ./ct
Tue Oct  5 00:00:00 2004

This problem also observed with R 1.6.0 and R 1.8.1 (RedHat 7.3)
The timezone doesn't seem to matter - this is just the first date that tripped
over this problem.


[Rd] POSIX time anomaly (PR#7317)
mcintosh@research.telcordia.com