Re: Trying to use AUTHOR_DATE

3 messages, 3 authors, 2016-06-15 · open the first message on its own page

Re: Trying to use AUTHOR_DATE

From: Russ Allbery <hidden>
Date: 2016-06-15 22:41:55

Linus Torvalds [off-list ref] writes:
It also seems to do so in a particularly stupid way, and David
Woodhouses suggestion of just using mktime() on Jan 1st, 1970, seems to
be much simpler than what curl does.
Because of daylight savings time, this doesn't actually work.  I know from
personal experience; this is the tactic that I took at first when writing
INN's date parser and was educated by test failures.

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>

Re: Trying to use AUTHOR_DATE

From: David Woodhouse <dwmw2@infradead.org>
Date: 2016-06-15 22:41:55

On Fri, 2005-04-29 at 21:32 -0700, Russ Allbery wrote:
Linus Torvalds [off-list ref] writes:
quoted
It also seems to do so in a particularly stupid way, and David
Woodhouses suggestion of just using mktime() on Jan 1st, 1970, seems to
be much simpler than what curl does.
Because of daylight savings time, this doesn't actually work.  I know from
personal experience; this is the tactic that I took at first when writing
INN's date parser and was educated by test failures.
Eww. The time functions we have to play with _really_ suck, don't they?
How about this...

Signed-off-by: David Woodhouse <dwmw2@infradead.org>

commit-tree.c: needs update
Index: commit-tree.c
===================================================================
--- c3aa1e6b53cc59d5fbe261f3f859584904ae3a63/commit-tree.c  (mode:100644 sha1:23de13361944ad7ba7c5320cf7cdd04e81842c60)
+++ uncommitted/commit-tree.c  (mode:100644)
@@ -213,10 +213,18 @@
 	if (*(skipfws(p + 5)))
 		return;
 
-	then = mktime(&tm); /* mktime appears to ignore the GMT offset, stupidly */
+	tm.tm_gmtoff = 0;
+	tm.tm_isdst = -1;
+
+	then = mktime(&tm);
 	if (then == -1)
 		return;
 
+	/* mktime always uses localtime, regardless of the tm_gmtoff field.
+	   It does, however, honour 'tm_isdst'; stupidly. Thankfully, it does
+	   at least tell us the offset it decided to use, so we can compensate
+	   for it */
+	then += tm.tm_gmtoff;
 	then -= offset;
 
 	snprintf(result, maxlen, "%lu %5.5s", then, p);
-- 
dwmw2

Re: Trying to use AUTHOR_DATE

From: Edgar Toernig <hidden>
Date: 2016-06-15 22:41:55

David Woodhouse wrote:
Eww. The time functions we have to play with _really_ suck, don't they?
How about this...

+	then += tm.tm_gmtoff;
tm_gmtoff is not available everywhere - POSIX doesn't even mention it (BSD?).

Oh btw, when we are about sucking time functions: the %s and %z strftime-
sequences used further down are also non-standard (POSIX has no %s, old
libc has neither %s nor %z).

A possible workaround:

void make_datestamp(char *buf)
{
	time_t now;
	struct tm *tm;
	int tz;

	time(&now);

	tm = localtime(&now); /* get timezone and tm_isdst */
	tz = -timezone / 60;
	if (tm->tm_isdst > 0)
		tz += 60;

	sprintf(buf, "%lu %+05d", now, tz/60*100+tz%60);
}

That *should* work on any POSIX system but who knows ...

Ciao, ET.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help