git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Russ Allbery <rra@stanford.edu>
To: git@vger.kernel.org
Subject: Re: Date handling.
Date: Sun, 24 Apr 2005 18:32:01 -0700	[thread overview]
Message-ID: <87br83wsj2.fsf@windlord.stanford.edu> (raw)
In-Reply-To: <20050425012216.GH29939@delft.aura.cs.cmu.edu> (Jan Harkes's message of "Sun, 24 Apr 2005 21:22:23 -0400")

Jan Harkes <jaharkes@cs.cmu.edu> writes:

> As Russ mentioned, that probably doesn't work with daylight savings
> time. However I did some testing and it looks like the following lines
> around mktime make it work as we would expect.

>     tm.tm_isdst = -1;
>     then = mktime(&tm);
>     then += tm.tm_gmtoff;

> Attached is the program I used to test it, it seems pretty much unfazed
> by changes to the TZ environment variable. Although I tested around a
> daylight savings time switch, I'm still not 100% sure if it doesn't mess
> up in some corner case.

I don't know what sort of portability you're striving for, but many
platforms don't have tm.tm_gmtoff.  But reimplementing mktime from scratch
isn't particularly hard so long as you don't need some of the "extra"
features of mktime (canonicalizing a struct tm or accepting out of range
values and doing the "right thing").

I came in a little late to this discussion, but I gather that the overall
goal here is parsing RFC 2822 dates.  You're all certainly welcome to take
the code that I wrote for INN to do this if you wish, although it parses
the full RFC 2822 syntax and therefore may accept things you consider
insane (comments, newlines, etc.)  Or you're welcome to cherry-pick bits
and pieces out of it (like mktime_utc).  This code has a fairly extensive
test suite and has also been tested against the old INN parsedate function
on ~2M Usenet articles.

All of this code is my own work, and as far as I'm concerned it's in the
public domain or as close of an approximation that one can get to that in
your local legal environment.

The code is largish and needs some Autoconf support, so I won't just send
it to the list unless someone wants it, but let me know if you do.  You
can also get it by downloading INN from:

    <ftp://ftp.isc.org/isc/inn/snapshots/>

(getting the latest CURRENT snapshot) and looking in lib/date.c.  You
don't need the parsedate_nntp stuff, and you probably don't care about
parsedate_rfc2822_lax, which accepts common violations of RFC 2822 syntax
found in Usenet messages.  The test suite is in tests/lib/date-t.c.

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

  reply	other threads:[~2005-04-25  1:28 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
2005-04-24  6:43           ` Russ Allbery
2005-04-25  1:22           ` Jan Harkes
2005-04-25  1:32             ` Russ Allbery [this message]
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=87br83wsj2.fsf@windlord.stanford.edu \
    --to=rra@stanford.edu \
    --cc=git@vger.kernel.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).