This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: mktime()
On Aug 24, 2011, at 7:48 AM, Steven Abner wrote:
>> Can you please send the simple testcase?
Hi;
A better test case which will expose also what I call "spring_forward_gap_bug". I didn't know at the time but this test will pick up the case glibc credits to Andreas Jaeger (1998). It can be adapted to other zones, as I did to include the glibc case. It's a butchered version from a much larger test, and set up in hourly increments since you have a grey area, "/* we let user decide or leave as -1 */".
extern time_t mktime(struct tm *tmPtr);
extern struct tm *localtime_r(const time_t *timer, struct tm *tmPtr);
#define MKTIME mktime
#define LCTIME localtime_r
static struct {
int y0, y1;
char *sfStr, *tzStr;
} sftests[ ] = {
//536457600, 1167609600, "PST8PDT,M4.1.0,M10.5.0", "America/Vancouver" //years 1987-2007
883612800, 1167609600, "PST8PDT,M4.1.0,M10.5.0", "America/Vancouver" //years 1998-2007
};
static void
standard_format(void) {
int i, cy0;
for (i = 0; i < ((int) (sizeof (sftests) / sizeof (sftests[0]))); i++) {
setenv("TZ", sftests[i].sfStr, 1);
for (cy0 = sftests[i].y0; cy0 < sftests[i].y1; cy0 += 3600) {
struct tm mtm, ptm;
memset(&mtm, 0, sizeof(struct tm));
mtm.tm_sec = cy0;
mtm.tm_year = 70;
mtm.tm_isdst = -1;
time_t t0 = MKTIME(&mtm);
LCTIME(&t0, &ptm);
if ((memcmp(&mtm, &ptm, (sizeof(int) * 9))))
printf("difference (20) %d\n", (int)cy0);
}
}
}
Cheers
Steve
Sorry, I saw you patched, so use if you wish