Added modified.strftime template, refactored test_template.py

This commit is contained in:
Rhet Turnbull
2021-01-13 06:19:41 -08:00
parent 250697c4a2
commit 088476c591
3 changed files with 114 additions and 151 deletions

View File

@@ -82,11 +82,11 @@ TEMPLATE_SUBSTITUTIONS = {
"{modified.hour}": "2-digit hour of the photo modification time; uses creation date if photo is not modified",
"{modified.min}": "2-digit minute of the photo modification time; uses creation date if photo is not modified",
"{modified.sec}": "2-digit second of the photo modification time; uses creation date if photo is not modified",
# "{modified.strftime}": "Apply strftime template to file modification date/time. Should be used in form "
# + "{modified.strftime,TEMPLATE} where TEMPLATE is a valid strftime template, e.g. "
# + "{modified.strftime,%Y-%U} would result in year-week number of year: '2020-23'. "
# + "If used with no template will return null value. "
# + "See https://strftime.org/ for help on strftime templates.",
"{modified.strftime}": "Apply strftime template to file modification date/time. Should be used in form "
+ "{modified.strftime,TEMPLATE} where TEMPLATE is a valid strftime template, e.g. "
+ "{modified.strftime,%Y-%U} would result in year-week number of year: '2020-23'. "
+ "If used with no template will return null value. Uses creation date if photo is not modified. "
+ "See https://strftime.org/ for help on strftime templates.",
"{today.date}": "Current date in iso format, e.g. '2020-03-22'",
"{today.year}": "4-digit year of current date",
"{today.yy}": "2-digit year of current date",
@@ -797,6 +797,15 @@ class PhotoTemplate:
if self.photo.date_modified
else DateTimeFormatter(self.photo.date).sec
)
elif field == "modified.strftime":
if default:
try:
date = self.photo.date_modified or self.photo.date
value = date.strftime(default)
except:
raise ValueError(f"Invalid strftime template: '{default}'")
else:
value = None
elif field == "today.date":
value = DateTimeFormatter(self.today).date
elif field == "today.year":