cleaned up formatDate function
This commit is contained in:
parent
c40dc034ff
commit
9ac168ab9c
|
@ -88,20 +88,15 @@ def downloadImage(url, path):
|
||||||
|
|
||||||
|
|
||||||
def formatDate(date, template):
|
def formatDate(date, template):
|
||||||
if 'YYYY' in template:
|
elements = {
|
||||||
template = template.replace('YYYY', str(date['year']))
|
'year': ['YYYY', 'YY', 'Y'],
|
||||||
if 'YY' in template:
|
'month': ['MM', 'M'],
|
||||||
template = template.replace('YY', str(date['year']))
|
'day': ['DD', 'D']
|
||||||
if 'Y' in template:
|
}
|
||||||
template = template.replace('Y', str(date['year']))
|
for element, placeholders in elements.items():
|
||||||
if 'MM' in template:
|
for placeholder in placeholders:
|
||||||
template = template.replace('MM', str(date['month']))
|
if placeholder in template:
|
||||||
if 'M' in template:
|
template = template.replace(placeholder, str(date[element]))
|
||||||
template = template.replace('M', str(date['month']))
|
|
||||||
if 'DD' in template:
|
|
||||||
template = template.replace('DD', str(date['day']))
|
|
||||||
if 'D' in template:
|
|
||||||
template = template.replace('D', str(date['day']))
|
|
||||||
return template
|
return template
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue