Parsing text into dates?

John Machin sjmachin at lexicon.net
Mon May 16 19:01:03 EDT 2005


On 16 May 2005 13:59:31 -0700, "Thomas W" <thomas.weholt at gmail.com>
wrote:

>I'm developing a web-application where the user sometimes has to enter
>dates in plain text, allthough a format may be provided to give clues.
>On the server side this piece of text has to be parsed into a datetime
>python-object. Does anybody have any pointers on this?
>
>Besides the actual parsing, my main concern is the different locale
>date formats and how to be able to parse those strange us-like
>"month/day/year" compared to the clever and intuitive european-style
>"day/month/year" etc.

<rant>
Well I'm from a locale that uses the dd/mm/yyyy style and I think it's
only marginally less stupid than the mm/dd/yyyy style.
</rant>

How much intuition is required to determine in an international
context what was meant by 01/12/2004? First of December or 12th of
January? The consequences of misinterpretation can be enormous.

If this application is being deployed from a central server where the
users can be worldwide, you have two options:

(a) try to work out somehow what the user's locale is, and then work
with dates in the legacy format "appropriate" to the locale.

(b) Use the considerably-less-stupid ISO 8601 standard format
yyyy-mm-dd (e.g. 2004-12-01) -- throughout your web-application, not
just in your data entry. 

Having said all of that, [bottom-up question] how are you handling
locale differences in language, script, currency symbol, decimal
"point", thousands separator, postal address formats, surname /
given-name order, etc etc etc? [top-down question] What *is* your
target audience?





More information about the Python-list mailing list