git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: Jan Harkes <jaharkes@cs.cmu.edu>
Cc: Linus Torvalds <torvalds@osdl.org>, git@vger.kernel.org
Subject: Re: Date handling.
Date: Sun, 24 Apr 2005 16:38:49 +1000	[thread overview]
Message-ID: <1114324729.3419.78.camel@localhost.localdomain> (raw)
In-Reply-To: <20050424030416.GE16751@delft.aura.cs.cmu.edu>

On Sat, 2005-04-23 at 23:04 -0400, Jan Harkes wrote:
> 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.

Ewww. I missed that in the documentation. I suppose I should have worked
it out having empirically determined that it ignores the tm_gmtoff
field.

> The question is, do we want to just calculate the time_t offset
> ourselves without using mktime, or force the TZ environment to UTC.

I don't think we want to be in the business of counting leap seconds; we
need to let the system do it. I don't much like setting TZ to UTC though
-- how about we use your test case to find the offset and subtract that?

Does this work?

Index: commit-tree.c
===================================================================
--- 31e9af73983d640090508b06784ef7db4816c957/commit-tree.c  (mode:100644 sha1:c0b07f89286c3f6cceae8122b4c3142c8efaf8e1)
+++ uncommitted/commit-tree.c  (mode:100664)
@@ -138,10 +138,14 @@
 	struct tm tm;
 	char *p;
 	int i, offset;
-	time_t then;
+	time_t then, localofs;
 
 	memset(&tm, 0, sizeof(tm));
 
+	tm.tm_mday = 1;
+	tm.tm_year = 70;
+	localofs = mktime(&tm);
+
 	/* Skip day-name */
 	p = skipfws(date);
 	if (!isdigit(*p)) {
@@ -246,7 +250,9 @@
 	if (*(skipfws(p + 5)))
 		return;
 
-	then = mktime(&tm); /* mktime appears to ignore the GMT offset, stupidly */
+	/* No way to convert to a time_t and honour tm_gmtoff; we have to
+	   do the evil trick by subtracting the local offset */
+	then = mktime(&tm) - localofs;
 	if (then == -1)
 		return;
 


-- 
dwmw2


  parent reply	other threads:[~2005-04-24  6:34 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-14  8:16 Date handling David Woodhouse
2005-04-14  9:00 ` Linus Torvalds
2005-04-14  9:12   ` Linus Torvalds
2005-04-14 17:38     ` David Woodhouse
2005-04-14 19:19       ` tony.luck
2005-04-14 19:23         ` David Woodhouse
2005-04-24  3:04       ` Jan Harkes
2005-04-24  3:33         ` James Purser
2005-04-24  6:38         ` David Woodhouse [this message]
2005-04-24  6:43           ` Russ Allbery
2005-04-25  1:22           ` Jan Harkes
2005-04-25  1:32             ` Russ Allbery
2005-04-14  9:31   ` David Woodhouse
  -- strict thread matches above, loose matches on Subject: below --
2005-04-14 19:42 Luck, Tony
2005-04-14 20:54 ` David Woodhouse
2005-04-14 21:01   ` H. Peter Anvin
2005-04-14 21:48     ` David Woodhouse
2005-04-15  5:02 ` Paul Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1114324729.3419.78.camel@localhost.localdomain \
    --to=dwmw2@infradead.org \
    --cc=git@vger.kernel.org \
    --cc=jaharkes@cs.cmu.edu \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).