1 Return-Path: <blakej@foo.net>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 4C880431FB6
\r
6 for <notmuch@notmuchmail.org>; Mon, 5 Nov 2012 07:47:31 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id 0yx8uOLeaIz7 for <notmuch@notmuchmail.org>;
\r
16 Mon, 5 Nov 2012 07:47:30 -0800 (PST)
\r
17 Received: from foo.net (70-36-235-136.dsl.static.sonic.net [70.36.235.136])
\r
18 (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 70D62431FAE
\r
21 for <notmuch@notmuchmail.org>; Mon, 5 Nov 2012 07:47:30 -0800 (PST)
\r
22 Received: from foo.net (localhost [127.0.0.1])
\r
23 by foo.net (8.14.5+Sun/8.14.5) with ESMTP id qA5FlM1X002593;
\r
24 Mon, 5 Nov 2012 07:47:22 -0800 (PST)
\r
25 To: Tomi Ollila <tomi.ollila@iki.fi>
\r
26 Subject: Re: [PATCH 10/10] timegm: add portable implementation (Solaris
\r
28 In-Reply-To: Your message of "Mon, 05 Nov 2012 14:09:33 +0200."
\r
29 <m2txt4jloi.fsf@guru.guru-group.fi>
\r
31 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
\r
32 Content-ID: <2591.1352130440.0@foo.net>
\r
33 Date: Mon, 05 Nov 2012 07:47:22 -0800
\r
34 Message-ID: <2592.1352130442@foo.net>
\r
35 From: Blake Jones <blakej@foo.net>
\r
36 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0.2
\r
37 (foo.net [127.0.0.1]); Mon, 05 Nov 2012 07:47:22 -0800 (PST)
\r
38 Cc: notmuch@notmuchmail.org
\r
39 X-BeenThere: notmuch@notmuchmail.org
\r
40 X-Mailman-Version: 2.1.13
\r
42 List-Id: "Use and development of the notmuch mail system."
\r
43 <notmuch.notmuchmail.org>
\r
44 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
46 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
47 List-Post: <mailto:notmuch@notmuchmail.org>
\r
48 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
49 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
50 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
51 X-List-Received-Date: Mon, 05 Nov 2012 15:47:31 -0000
\r
53 ------- =_aaaaaaaaaa0
\r
54 Content-Type: text/plain; charset="us-ascii"
\r
55 Content-ID: <2591.1352130440.1@foo.net>
\r
57 > Yet another idea for an alternative. Compile by entering 'sh xtimegm.c'
\r
58 > and then run ./xtimegm
\r
60 > Simple cases seems to work. Dst change may (or then may not) give one
\r
61 > hour difference to the expected. The test "coverage" could be easily
\r
62 > expanded to that ;)
\r
64 > Hmm, I also found this:
\r
65 > http://lists.gnu.org/archive/html/bug-gnulib/2003-09/msg00004.html
\r
66 > which does 2 mktime's and one gmtime_r (without allocating tg!)...
\r
67 > Pick any of these 3 -- or something different (e.g. less NIH if there is)
\r
69 Of these two, I would probably lean slightly toward the latter, in that
\r
70 it relies more on libc for the time zone handling logic.
\r
72 But in general, this seems to me like a case where an explicit
\r
73 implementation like mine is less prone to failure, because it doesn't
\r
74 need to worry about time zones at all. The other approaches rely on
\r
75 letting libc do all the hard work of time zone manipulation, and then
\r
76 reading the tea leaves to find a way to undo it. I would guess that if
\r
77 some change in the time standards is going to break one of these
\r
78 implementations, it's going to be some new time zone specification, not
\r
79 a change in the number of days in a month. :)
\r
81 For what it's worth, I used the attached program to test my
\r
82 implementation, and it passed.
\r
87 ------- =_aaaaaaaaaa0
\r
88 Content-Type: text/plain; charset="us-ascii"
\r
89 Content-ID: <2591.1352130440.2@foo.net>
\r
96 return ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0));
\r
100 * This is a simple implementation of timegm() which does what is needed
\r
101 * by parse-time-string.c -- just turns the "struct tm" into a GMT time_t.
\r
102 * It does not normalize any of the fields of the "struct tm", nor does
\r
103 * it set tm_wday or tm_yday.
\r
106 timegm(struct tm *tm)
\r
108 int monthlen[2][12] = {
\r
109 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
\r
110 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
\r
112 int year, month, days;
\r
114 days = 365 * (tm->tm_year - 70);
\r
115 for (year = 70; year < tm->tm_year; year++) {
\r
116 if (leapyear(1900 + year)) {
\r
120 for (month = 0; month < tm->tm_mon; month++) {
\r
121 days += monthlen[leapyear(1900 + year)][month];
\r
123 days += tm->tm_mday - 1;
\r
125 return ((((days * 24) + tm->tm_hour) * 60 + tm->tm_min) * 60 +
\r
130 #include <stdlib.h>
\r
131 #include <unistd.h>
\r
136 const int monthlen[2][12] = {
\r
137 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
\r
138 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
\r
141 struct tm tm, *tmp;
\r
144 for (i = 0; i < niter; i++) {
\r
145 tm.tm_year = (lrand48() % 67) + 70;
\r
146 tm.tm_mon = lrand48() % 12;
\r
148 t = (lrand48() % 31) + 1;
\r
149 } while (t > monthlen[leapyear(1900 + tm.tm_year)][tm.tm_mon]);
\r
151 tm.tm_hour = lrand48() % 24;
\r
152 tm.tm_min = lrand48() % 60;
\r
153 tm.tm_sec = lrand48() % 60;
\r
158 if (tmp->tm_sec != tm.tm_sec ||
\r
159 tmp->tm_min != tm.tm_min ||
\r
160 tmp->tm_hour != tm.tm_hour ||
\r
161 tmp->tm_mday != tm.tm_mday ||
\r
162 tmp->tm_mon != tm.tm_mon ||
\r
163 tmp->tm_year != tm.tm_year) {
\r
164 printf("%4d-%02d-%02d %02d:%02d:%02d -> "
\r
165 "%4d-%02d-%02d %02d:%02d:%02d\n",
\r
166 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
\r
167 tm.tm_hour, tm.tm_min, tm.tm_sec,
\r
168 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
\r
169 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
\r
176 time_test(int niter)
\r
182 for (i = 0; i < niter; i++) {
\r
183 st = (time_t)lrand48();
\r
189 printf("%d -> %d (%4d-%02d-%02d %02d:%02d:%02d)\n",
\r
191 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
\r
192 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
\r
200 const int niter = 10000000;
\r
210 ------- =_aaaaaaaaaa0--
\r