[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] posixtm: don't reject a time with "60" as the number of se
From: |
Paolo Bonzini |
Subject: |
Re: [PATCH] posixtm: don't reject a time with "60" as the number of seconds |
Date: |
Tue, 15 Sep 2009 11:26:27 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.1) Gecko/20090814 Fedora/3.0-2.6.b3.fc11 Lightning/1.0pre Thunderbird/3.0b3 |
Going backwards from "cal 1 1" you can see that in
the Julian calendar 01-Jan-0000 was a Thursday, but that's not so
relevant.
However cal can help seeing that 01-Jan-0000 is a Saturday in
Gregorian proleptic calendar (i.e. extending Gregorian calendar before
the day when it was adopted). 400 years have 146097 days, which is
divisible by 7, and 01-Jan-2000 was a Saturday.
If that's true, then this new test failure suggests there's a bug in mktime.
For the record, GNU Smalltalk gives the same answer.
But mktime seems to work here:
#include <stdio.h>
#include <time.h>
#include <string.h>
int main()
{
const char days[7][4] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
struct tm tm;
time_t t;
memset (&tm, 0, sizeof (tm));
tm.tm_mon = 0;
tm.tm_mday = 1;
tm.tm_year = -1900;
setenv ("TZ", "GMT");
t = mktime (&tm);
printf ("%ld\n", t);
printf ("%s %d\n", days[tm.tm_wday], tm.tm_yday);
printf ("%s", ctime(&t));
tm = *gmtime(&t);
printf ("%d %d %d %s\n", tm.tm_mon, tm.tm_mday, tm.tm_year,
days[tm.tm_wday]);
}
$ ./a.out
-62167219200
Sat 0
Sat Jan 1 00:00:00 0
0 1 -1900 Sat
Paolo
- [PATCH] posixtm: don't reject a time with "60" as the number of seconds, Jim Meyering, 2009/09/14
- Re: [PATCH] posixtm: don't reject a time with "60" as the number of seconds, Paolo Bonzini, 2009/09/14
- Re: [PATCH] posixtm: don't reject a time with "60" as the number of seconds, Jim Meyering, 2009/09/15
- Re: [PATCH] posixtm: don't reject a time with "60" as the number of seconds, Paolo Bonzini, 2009/09/16
- Re: [PATCH] posixtm: don't reject a time with "60" as the number of seconds, Jim Meyering, 2009/09/16
- Re: [PATCH] posixtm: don't reject a time with "60" as the number of seconds, Jim Meyering, 2009/09/19
- Re: [PATCH] posixtm: don't reject a time with "60" as the number of seconds, Eric Blake, 2009/09/19
- Re: [PATCH] posixtm: don't reject a time with "60" as the number of seconds, Jim Meyering, 2009/09/19