Re: Date handling.
- From
Jan Harkes <jaharkes@cs.cmu.edu>
- Date
- Apr 24, 2005, 03:04 UTC
- Message-ID
- <20050424030416.GE16751@delft.aura.cs.cmu.edu>
- In-Reply-To
- <1113500316.27227.8.camel@hades.cambridge.redhat.com>
On Thu, Apr 14, 2005 at 06:38:36PM +0100, David Woodhouse wrote:
> +/* Gr. strptime is crap for this; it doesn't have a way to require RFC2822
> + (i.e. English) day/month names, and it doesn't work correctly with %z. */
> +static void parse_rfc2822_date(char *date, char *result, int maxlen)
> +{...
> + then = mktime(&tm); /* mktime appears to ignore the GMT offset, stupidly */
I noticed that some commit timestamps seemed to be off, looking into it a bit more it seems like mktime is influenced by the setting of the local TZ environment. However in parse_rfc2822_date we are trying to interpret a time in the timezone of the original author not in the timezone of the committer.
Here is a short test program that I believe shows the problem.
The question is, do we want to just calculate the time_t offset ourselves without using mktime, or force the TZ environment to UTC.
Jan
/* cc -o mktime mktime.c ; ./mktime * * I get the following output, * current 18000 * TZ=EST 18000 * TZ=UTC 0 * TZ=CET -3600 */
#include <time.h> #include <stdlib.h> #include <stdio.h>
int main(int argc, char **argv)
{
struct tm tm = { 0, };
time_t zero; /* 1970-01-01 00:00:00 UTC, should map to 'time_t 0' */
tm.tm_mday = 1;
tm.tm_year = 70;
zero = mktime(&tm); printf("current %d\n", zero);
setenv("TZ", "EST", 1); zero = mktime(&tm); printf("TZ=EST %d\n", zero);
setenv("TZ", "UTC", 1); zero = mktime(&tm); printf("TZ=UTC %d\n", zero);
setenv("TZ", "CET", 1); zero = mktime(&tm); printf("TZ=CET %d\n", zero);
}