From 4144c8d76f473fc062082fc6529fb418f7dcf5f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88kull=20So=CC=81lberg=20Au=C3=B0unsson?= Date: Wed, 23 Nov 2011 20:35:18 +0000 Subject: [PATCH] More forgiving date strings. --- pelican/utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pelican/utils.py b/pelican/utils.py index cd7507ee..27159a89 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -17,8 +17,12 @@ def get_date(string): If no format matches the given date, raise a ValuEerror """ - formats = ['%Y-%m-%d %H:%M', '%Y/%m/%d %H:%M', '%Y-%m-%d', '%Y/%m/%d', - '%d/%m/%Y', '%d.%m.%Y', '%d.%m.%Y %H:%M', '%Y-%m-%d %H:%M:%S'] + string = re.sub(' +', ' ', string) + formats = ['%Y-%m-%d %H:%M', '%Y/%m/%d %H:%M', + '%Y-%m-%d', '%Y/%m/%d', + '%d-%m-%Y', '%Y-%d-%m', # Weird ones + '%d/%m/%Y', '%d.%m.%Y', + '%d.%m.%Y %H:%M', '%Y-%m-%d %H:%M:%S'] for date_format in formats: try: return datetime.strptime(string, date_format)