From 2f57abd23cabe57bcf667a1713c37689b330a702 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Thu, 31 Dec 2020 13:07:00 -0800 Subject: [PATCH] Fixed modified template to use creation time if no modificationd date, issue #312 --- README.md | 60 +++++++++++++++++++++++--------------- osxphotos/_version.py | 2 +- osxphotos/phototemplate.py | 48 +++++++++++++++--------------- tests/test_template.py | 22 ++++++++------ 4 files changed, 74 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index 219ad727..9d9ee8af 100644 --- a/README.md +++ b/README.md @@ -740,27 +740,39 @@ Substitution Description https://strftime.org/ for help on strftime templates. {modified.date} Photo's modification date in ISO format, - e.g. '2020-03-22' -{modified.year} 4-digit year of photo modification time -{modified.yy} 2-digit year of photo modification time + e.g. '2020-03-22'; uses creation date if + photo is not modified +{modified.year} 4-digit year of photo modification time; + uses creation date if photo is not modified +{modified.yy} 2-digit year of photo modification time; + uses creation date if photo is not modified {modified.mm} 2-digit month of the photo modification time - (zero padded) + (zero padded); uses creation date if photo + is not modified {modified.month} Month name in user's locale of the photo - modification time + modification time; uses creation date if + photo is not modified {modified.mon} Month abbreviation in the user's locale of - the photo modification time + the photo modification time; uses creation + date if photo is not modified {modified.dd} 2-digit day of the month (zero padded) of - the photo modification time + the photo modification time; uses creation + date if photo is not modified {modified.dow} Day of week in user's locale of the photo - modification time + modification time; uses creation date if + photo is not modified {modified.doy} 3-digit day of year (e.g Julian day) of photo modification time, starting from 1 - (zero padded) -{modified.hour} 2-digit hour of the photo modification time + (zero padded); uses creation date if photo + is not modified +{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 + time; uses creation date if photo is not + modified {modified.sec} 2-digit second of the photo modification - time + time; uses creation date if photo is not + modified {today.date} Current date in iso format, e.g. '2020-03-22' {today.year} 4-digit year of current date @@ -2297,18 +2309,18 @@ The following template field substitutions are availabe for use with `PhotoInfo. |{created.min}|2-digit minute of the photo creation time| |{created.sec}|2-digit second of the photo creation time| |{created.strftime}|Apply strftime template to file creation date/time. Should be used in form {created.strftime,TEMPLATE} where TEMPLATE is a valid strftime template, e.g. {created.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.date}|Photo's modification date in ISO format, e.g. '2020-03-22'| -|{modified.year}|4-digit year of photo modification time| -|{modified.yy}|2-digit year of photo modification time| -|{modified.mm}|2-digit month of the photo modification time (zero padded)| -|{modified.month}|Month name in user's locale of the photo modification time| -|{modified.mon}|Month abbreviation in the user's locale of the photo modification time| -|{modified.dd}|2-digit day of the month (zero padded) of the photo modification time| -|{modified.dow}|Day of week in user's locale of the photo modification time| -|{modified.doy}|3-digit day of year (e.g Julian day) of photo modification time, starting from 1 (zero padded)| -|{modified.hour}|2-digit hour of the photo modification time| -|{modified.min}|2-digit minute of the photo modification time| -|{modified.sec}|2-digit second of the photo modification time| +|{modified.date}|Photo's modification date in ISO format, e.g. '2020-03-22'; uses creation date if photo is not modified| +|{modified.year}|4-digit year of photo modification time; uses creation date if photo is not modified| +|{modified.yy}|2-digit year of photo modification time; uses creation date if photo is not modified| +|{modified.mm}|2-digit month of the photo modification time (zero padded); uses creation date if photo is not modified| +|{modified.month}|Month name in user's locale of the photo modification time; uses creation date if photo is not modified| +|{modified.mon}|Month abbreviation in the user's locale of the photo modification time; uses creation date if photo is not modified| +|{modified.dd}|2-digit day of the month (zero padded) of the photo modification time; uses creation date if photo is not modified| +|{modified.dow}|Day of week in user's locale of the photo modification time; uses creation date if photo is not modified| +|{modified.doy}|3-digit day of year (e.g Julian day) of photo modification time, starting from 1 (zero padded); uses creation date if photo is not modified| +|{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| |{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| diff --git a/osxphotos/_version.py b/osxphotos/_version.py index 8c62e9ae..af0a971e 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,5 +1,5 @@ """ version info """ -__version__ = "0.39.2" +__version__ = "0.39.3" diff --git a/osxphotos/phototemplate.py b/osxphotos/phototemplate.py index d4a61bb9..92669dc0 100644 --- a/osxphotos/phototemplate.py +++ b/osxphotos/phototemplate.py @@ -70,18 +70,18 @@ TEMPLATE_SUBSTITUTIONS = { + "{created.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.date}": "Photo's modification date in ISO format, e.g. '2020-03-22'", - "{modified.year}": "4-digit year of photo modification time", - "{modified.yy}": "2-digit year of photo modification time", - "{modified.mm}": "2-digit month of the photo modification time (zero padded)", - "{modified.month}": "Month name in user's locale of the photo modification time", - "{modified.mon}": "Month abbreviation in the user's locale of the photo modification time", - "{modified.dd}": "2-digit day of the month (zero padded) of the photo modification time", - "{modified.dow}": "Day of week in user's locale of the photo modification time", - "{modified.doy}": "3-digit day of year (e.g Julian day) of photo modification time, starting from 1 (zero padded)", - "{modified.hour}": "2-digit hour of the photo modification time", - "{modified.min}": "2-digit minute of the photo modification time", - "{modified.sec}": "2-digit second of the photo modification time", + "{modified.date}": "Photo's modification date in ISO format, e.g. '2020-03-22'; uses creation date if photo is not modified", + "{modified.year}": "4-digit year of photo modification time; uses creation date if photo is not modified", + "{modified.yy}": "2-digit year of photo modification time; uses creation date if photo is not modified", + "{modified.mm}": "2-digit month of the photo modification time (zero padded); uses creation date if photo is not modified", + "{modified.month}": "Month name in user's locale of the photo modification time; uses creation date if photo is not modified", + "{modified.mon}": "Month abbreviation in the user's locale of the photo modification time; uses creation date if photo is not modified", + "{modified.dd}": "2-digit day of the month (zero padded) of the photo modification time; uses creation date if photo is not modified", + "{modified.dow}": "Day of week in user's locale of the photo modification time; uses creation date if photo is not modified", + "{modified.doy}": "3-digit day of year (e.g Julian day) of photo modification time, starting from 1 (zero padded); uses creation date if photo is not modified", + "{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'. " @@ -679,73 +679,73 @@ class PhotoTemplate: value = ( DateTimeFormatter(self.photo.date_modified).date if self.photo.date_modified - else None + else DateTimeFormatter(self.photo.date).date ) elif field == "modified.year": value = ( DateTimeFormatter(self.photo.date_modified).year if self.photo.date_modified - else None + else DateTimeFormatter(self.photo.date).year ) elif field == "modified.yy": value = ( DateTimeFormatter(self.photo.date_modified).yy if self.photo.date_modified - else None + else DateTimeFormatter(self.photo.date).yy ) elif field == "modified.mm": value = ( DateTimeFormatter(self.photo.date_modified).mm if self.photo.date_modified - else None + else DateTimeFormatter(self.photo.date).mm ) elif field == "modified.month": value = ( DateTimeFormatter(self.photo.date_modified).month if self.photo.date_modified - else None + else DateTimeFormatter(self.photo.date).month ) elif field == "modified.mon": value = ( DateTimeFormatter(self.photo.date_modified).mon if self.photo.date_modified - else None + else DateTimeFormatter(self.photo.date).mon ) elif field == "modified.dd": value = ( DateTimeFormatter(self.photo.date_modified).dd if self.photo.date_modified - else None + else DateTimeFormatter(self.photo.date).dd ) elif field == "modified.dow": value = ( DateTimeFormatter(self.photo.date_modified).dow if self.photo.date_modified - else None + else DateTimeFormatter(self.photo.date).dow ) elif field == "modified.doy": value = ( DateTimeFormatter(self.photo.date_modified).doy if self.photo.date_modified - else None + else DateTimeFormatter(self.photo.date).doy ) elif field == "modified.hour": value = ( DateTimeFormatter(self.photo.date_modified).hour if self.photo.date_modified - else None + else DateTimeFormatter(self.photo.date).hour ) elif field == "modified.min": value = ( DateTimeFormatter(self.photo.date_modified).min if self.photo.date_modified - else None + else DateTimeFormatter(self.photo.date).min ) elif field == "modified.sec": value = ( DateTimeFormatter(self.photo.date_modified).sec if self.photo.date_modified - else None + else DateTimeFormatter(self.photo.date).sec ) elif field == "today.date": value = DateTimeFormatter(self.today).date diff --git a/tests/test_template.py b/tests/test_template.py index 532ffcd6..a38a0a6d 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -170,17 +170,21 @@ TEMPLATE_VALUES_DATE_MODIFIED = { } TEMPLATE_VALUES_DATE_NOT_MODIFIED = { + # uses creation date instead of modified date "{name}": "128FB4C6-0B16-4E7D-9108-FB2E90DA1546", "{original_name}": "IMG_1064", - "{modified.date}": "_", - "{modified.year}": "_", - "{modified.yy}": "_", - "{modified.mm}": "_", - "{modified.month}": "_", - "{modified.mon}": "_", - "{modified.dd}": "_", - "{modified.doy}": "_", - "{modified.dow}": "_", + "{modified.date}": "2020-02-04", + "{modified.year}": "2020", + "{modified.yy}": "20", + "{modified.mm}": "02", + "{modified.month}": "February", + "{modified.mon}": "Feb", + "{modified.dd}": "04", + "{modified.dow}": "Tuesday", + "{modified.doy}": "035", + "{modified.hour}": "19", + "{modified.min}": "07", + "{modified.sec}": "38", }