mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
More forgiving date strings.
This commit is contained in:
parent
aee3f661f4
commit
4144c8d76f
1 changed files with 6 additions and 2 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue