git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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);
}
Previous: David WoodhouseNext: James Purser
Message 7 of 13 in “Date handling.”
  1. David WoodhouseApr 14, 2005
  2. Linus TorvaldsApr 14, 2005
  3. Linus TorvaldsApr 14, 2005
  4. David WoodhouseApr 14, 2005
  5. tony.luck@intel.comApr 14, 2005
  6. David WoodhouseApr 14, 2005
  7. Jan HarkesApr 24, 2005
  8. James PurserApr 24, 2005
  9. David WoodhouseApr 24, 2005
  10. Russ AllberyApr 24, 2005
  11. Jan HarkesApr 25, 2005
  12. Russ AllberyApr 25, 2005
  13. David WoodhouseApr 14, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.