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

Re: Date parsing

From
Stephan Beyer <s-beyer@gmx.net>
Date
Jun 21, 2008, 21:52 UTC
Message-ID
<20080621215240.GD15111@leksak.fem-net>
In-Reply-To
<alpine.LFD.1.10.0806100942500.3101@woody.linux-foundation.org>
Hi,
Show 11 quoted lines
> > On Tue, Jun 10, 2008 at 5:10 PM, Brandon Casey <casey@nrlssc.navy.mil> wrote:
> > > Take a look at match_multi_number in date.c
> > > European ordering is preferred when the separator is '.'
> > 
> > Ok, then I'll use . in the future, that's nice :).
> 
> Well, there are safer ways to give the date.
> 
> If you do it in strict rfc822 format, you'll never have any confusion 
> what-so-ever. The "approxidate()" thing tries to parse any random input, 
> but it *is* meant to be excessively liberal.

Today I've been playing around with approxidate(), too, and I think I found some bug in date parsing. I let copy&paste speak...

Correct:

$ ./test-date "2008-07-01 23:59:59 +0200" 2008-07-01 23:59:59 +0200 -> 1214949599 +0200 -> Tue Jul 1 23:59:59 2008 2008-07-01 23:59:59 +0200 -> Tue Jul 1 23:59:59 2008

And even:

$ ./test-date "2008-07-01 24:00:00 +0200" 2008-07-01 24:00:00 +0200 -> 1214949600 +0200 -> Wed Jul 2 00:00:00 2008 2008-07-01 24:00:00 +0200 -> Wed Jul 2 00:00:00 2008

But then there's a jump in time:

$ ./test-date "2008-07-02 00:00:00 +0200" 2008-07-02 00:00:00 +0200 -> 1202335200 +0200 -> Wed Feb 6 23:00:00 2008 2008-07-02 00:00:00 +0200 -> Wed Feb 6 23:00:00 2008

$ ./test-date "2008-07-02 01:00:00 +0200" 2008-07-02 01:00:00 +0200 -> 1202338800 +0200 -> Thu Feb 7 00:00:00 2008 2008-07-02 01:00:00 +0200 -> Thu Feb 7 00:00:00 2008

If we let test-date just print the timestamp...
diff --git a/test-date.c b/test-date.c
index 62e8f23..18d53c1 100644
--- a/test-date.c
+++ b/test-date.c
@@ -11,10 +11,10 @@ int main(int argc, char **argv)
 		memcpy(result, "bad", 4);
 		parse_date(argv[i], result, sizeof(result));
 		t = strtoul(result, NULL, 0);
-		printf("%s -> %s -> %s", argv[i], result, ctime(&t));
+		printf("%s -> %lu\n", argv[i], t);
 
 		t = approxidate(argv[i]);
-		printf("%s -> %s\n", argv[i], ctime(&t));
+		printf("%s -> %lu\n", argv[i], t);
 	}
 	return 0;
 }
-- -- -- --

... then we get:

$ ./test-date "2008-07-01 23:59:59 +0200"
2008-07-01 23:59:59 +0200 -> 1214949599
2008-07-01 23:59:59 +0200 -> 1214949599

$ ./test-date "2008-07-02 00:00:00 +0200"
2008-07-02 00:00:00 +0200 -> 1202335200
2008-07-02 00:00:00 +0200 -> 1202335200

Also, with another timezone, we get:

$ ./test-date "2008-07-01 23:59:59 +0000"
2008-07-01 23:59:59 +0000 -> 1214956799
2008-07-01 23:59:59 +0000 -> 1214956799

$ ./test-date "2008-07-02 00:00:00 +0000"
2008-07-02 00:00:00 +0000 -> 1202342400
2008-07-02 00:00:00 +0000 -> 1202342400

Is something wrong in my format or is there a bug?

Providing timestamps works, of course ;-)

Regards,
  Stephan
-- 
Stephan Beyer <s-beyer@gmx.net>, PGP 0x6EDDD207FCC5040F
Previous: Sverre RabbelierNext: Linus Torvalds
Message 8 of 11 in “Date parsing”
  1. Sverre RabbelierJun 10, 2008
  2. Johannes SixtJun 10, 2008
  3. Sverre RabbelierJun 10, 2008
  4. Brandon CaseyJun 10, 2008
  5. Sverre RabbelierJun 10, 2008
  6. Linus TorvaldsJun 10, 2008
  7. Sverre RabbelierJun 10, 2008
  8. Stephan BeyerJun 21, 2008
  9. Linus TorvaldsJun 21, 2008
  10. Linus TorvaldsJun 21, 2008
  11. Stephan BeyerJun 21, 2008

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.