diff --git a/README.md b/README.md index 162cb752..4f7655ba 100644 --- a/README.md +++ b/README.md @@ -369,6 +369,8 @@ Substitution Description creation time {created.mon} Month abbreviation in the user's locale of the file creation time +{created.dd} 2-digit day of the month (zero padded) of + file creation time {created.doy} 3-digit day of year (e.g Julian day) of file creation time, starting from 1 (zero padded) {modified.date} Photo's modification date in ISO format, @@ -381,6 +383,8 @@ Substitution Description modification time {modified.mon} Month abbreviation in the user's locale of the file modification time +{modified.dd} 2-digit day of the month (zero padded) of + the file modification time {modified.doy} 3-digit day of year (e.g Julian day) of file modification time, starting from 1 (zero padded) @@ -1369,6 +1373,7 @@ The following substitutions are availabe for use with `PhotoInfo.render_template |{created.mm}|2-digit month of the file creation time (zero padded)| |{created.month}|Month name in user's locale of the file creation time| |{created.mon}|Month abbreviation in the user's locale of the file creation time| +|{created.dd}|2-digit day of the month (zero padded) of file creation time| |{created.doy}|3-digit day of year (e.g Julian day) of file creation time, starting from 1 (zero padded)| |{modified.date}|Photo's modification date in ISO format, e.g. '2020-03-22'| |{modified.year}|4-digit year of file modification time| @@ -1376,6 +1381,7 @@ The following substitutions are availabe for use with `PhotoInfo.render_template |{modified.mm}|2-digit month of the file modification time (zero padded)| |{modified.month}|Month name in user's locale of the file modification time| |{modified.mon}|Month abbreviation in the user's locale of the file modification time| +|{modified.dd}|2-digit day of the month (zero padded) of the file modification time| |{modified.doy}|3-digit day of year (e.g Julian day) of file modification time, starting from 1 (zero padded)| |{place.name}|Place name from the photo's reverse geolocation data, as displayed in Photos| |{place.country_code}|The ISO country code from the photo's reverse geolocation data| diff --git a/osxphotos/_version.py b/osxphotos/_version.py index 709950d9..3d49c8be 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,3 +1,3 @@ """ version info """ -__version__ = "0.29.2" +__version__ = "0.29.3" diff --git a/osxphotos/datetime_formatter.py b/osxphotos/datetime_formatter.py index d5fdeef3..1cd9b658 100644 --- a/osxphotos/datetime_formatter.py +++ b/osxphotos/datetime_formatter.py @@ -45,6 +45,12 @@ class DateTimeFormatter: mon = f"{self.dt.strftime('%b')}" return mon + @property + def dd(self): + """ 2-digit day of the month """ + dd = f"{self.dt.strftime('%d')}" + return dd + @property def doy(self): """ Julian day of year starting from 001 """ diff --git a/osxphotos/photoinfo/photoinfo.py b/osxphotos/photoinfo/photoinfo.py index 3c1bc001..da7887ff 100644 --- a/osxphotos/photoinfo/photoinfo.py +++ b/osxphotos/photoinfo/photoinfo.py @@ -836,6 +836,9 @@ class PhotoInfo: if lookup == "created.mon": return DateTimeFormatter(self.date).mon + if lookup == "created.dd": + return DateTimeFormatter(self.date).dd + if lookup == "created.doy": return DateTimeFormatter(self.date).doy @@ -877,6 +880,11 @@ class PhotoInfo: else None ) + if lookup == "modified.dd": + return ( + DateTimeFormatter(self.date_modified).dd if self.date_modified else None + ) + if lookup == "modified.doy": return ( DateTimeFormatter(self.date_modified).doy diff --git a/osxphotos/photoinfo/template.py b/osxphotos/photoinfo/template.py index 154344d5..198fcb5b 100644 --- a/osxphotos/photoinfo/template.py +++ b/osxphotos/photoinfo/template.py @@ -26,6 +26,7 @@ TEMPLATE_SUBSTITUTIONS = { "{created.mm}": "2-digit month of the file creation time (zero padded)", "{created.month}": "Month name in user's locale of the file creation time", "{created.mon}": "Month abbreviation in the user's locale of the file creation time", + "{created.dd}": "2-digit day of the month (zero padded) of file creation time", "{created.doy}": "3-digit day of year (e.g Julian day) of file creation time, starting from 1 (zero padded)", "{modified.date}": "Photo's modification date in ISO format, e.g. '2020-03-22'", "{modified.year}": "4-digit year of file modification time", @@ -33,6 +34,7 @@ TEMPLATE_SUBSTITUTIONS = { "{modified.mm}": "2-digit month of the file modification time (zero padded)", "{modified.month}": "Month name in user's locale of the file modification time", "{modified.mon}": "Month abbreviation in the user's locale of the file modification time", + "{modified.dd}": "2-digit day of the month (zero padded) of the file modification time", "{modified.doy}": "3-digit day of year (e.g Julian day) of file modification time, starting from 1 (zero padded)", "{place.name}": "Place name from the photo's reverse geolocation data, as displayed in Photos", "{place.country_code}": "The ISO country code from the photo's reverse geolocation data", diff --git a/tests/test_datetime_formatter.py b/tests/test_datetime_formatter.py new file mode 100644 index 00000000..2b88dfa4 --- /dev/null +++ b/tests/test_datetime_formatter.py @@ -0,0 +1,21 @@ +""" test datetime_formatter.DateTimeFormatter """ +import pytest + +def test_datetime_formatter(): + import datetime + import locale + from osxphotos.datetime_formatter import DateTimeFormatter + + locale.setlocale(locale.LC_ALL, "en_US") + + dt = datetime.datetime(2020,5,23) + dtf = DateTimeFormatter(dt) + + assert dtf.date == "2020-05-23" + assert dtf.year == "2020" + assert dtf.yy == "20" + assert dtf.month == "May" + assert dtf.mon == "May" + assert dtf.mm == "05" + assert dtf.dd == "23" + assert dtf.doy == "144" diff --git a/tests/test_template.py b/tests/test_template.py index a9ea3c4c..b7d7b605 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -29,6 +29,7 @@ TEMPLATE_VALUES = { "{created.mm}": "02", "{created.month}": "February", "{created.mon}": "Feb", + "{created.dd}": "04", "{created.doy}": "035", "{modified.date}": "2020-03-21", "{modified.year}": "2020", @@ -36,6 +37,7 @@ TEMPLATE_VALUES = { "{modified.mm}": "03", "{modified.month}": "March", "{modified.mon}": "Mar", + "{modified.dd}": "21", "{modified.doy}": "081", "{place.name}": "Washington, District of Columbia, United States", "{place.country_code}": "US", @@ -64,6 +66,7 @@ TEMPLATE_VALUES_DEU = { "{created.mm}": "02", "{created.month}": "Februar", "{created.mon}": "Feb", + "{created.dd}": "04", "{created.doy}": "035", "{modified.date}": "2020-03-21", "{modified.year}": "2020", @@ -71,6 +74,7 @@ TEMPLATE_VALUES_DEU = { "{modified.mm}": "03", "{modified.month}": "März", "{modified.mon}": "Mär", + "{modified.dd}": "21", "{modified.doy}": "081", "{place.name}": "Washington, District of Columbia, United States", "{place.country_code}": "US",