Enhanced parse_date supporting month names and custom formats

24 views
Skip to first unread message

Vinay Sajip

unread,
May 24, 2011, 6:58:18 AM5/24/11
to Python Babel
I've created an enhanced version of the babel.dates.parse_date
function which supports both month names and custom date formats. The
signature changes to parse_date(string, locale, fmt=None) - if fmt is
not specified,the default date format for the locale is used.

Example usage:

d = parse_date('17 grudnia 1969', 'pl_PL', 'd MMMM yyyy')
print(d)
d = parse_date('18 decembrie 1969', 'ro_RO', 'd MMMM yyyy')
print(d)
d = parse_date('19 декември 1969', 'bg_BG', 'd MMMM yyyy')
print(d)

would print

1969-12-17
1969-12-18
1969-12-19

Is this approach of any interest to the committers? A complete script
is available at

https://gist.github.com/988517

All feedback gratefully received.

Regards,

Vinay Sajip
Reply all
Reply to author
Forward
0 new messages