views:

100

answers:

2

I'm about to start working on a simple calendar app for a website I'm working on (using Django, but that fact's probably not relevant).

I'd like users to be able to enter when an event is in a text box like this:

  • Every Sunday evening at 7pm
  • Next Friday
  • Tuesday 1st Dec 2009

and have my application begin to make some guesses as to when they mean. I don't need it to promise to be right, just to be able to present the users with some guesses as to what they mean. Is there a Python library that does some of this? Bonus points if it's extensible to match more formats.

I don't care too much about timezones - for the purposes of my application it's safe to assume any times are in whatever timezone London happens to be in. I'll work that out once I've got some kind of yyyymmddhhiiss representation (or similar).

Apologies if there's a duplicate I've missed - I did have a look.

+1  A: 

There is http://code.google.com/p/parsedatetime/

Peter Hoffmann
It does make me nervous that when I check out from trunk and run the tests, 2 of them fail.
Dominic Rodger
Could you post the errors and file a bug? The author (Mike Tylor http://code-bear.com/bearlog/) works at seesmic and is a very capable coder.
Peter Hoffmann
Will do - I'll check tomorrow that I've not screwed something up in the way I've set it up and post back here with a link.
Dominic Rodger
Next time I won't be such a moron, and I'll download the version for the version of Python I have. All tests now pass. Ahem.
Dominic Rodger
+1  A: 

I proposed a pyparsing solution to this question, which seems similar to yours.

Paul McGuire