added created.dd and modified.dd to template system, closes #135

This commit is contained in:
Rhet Turnbull
2020-05-23 21:39:40 -07:00
parent af750dd2e3
commit 28935b0af9
7 changed files with 48 additions and 1 deletions

View File

@@ -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|

View File

@@ -1,3 +1,3 @@
""" version info """
__version__ = "0.29.2"
__version__ = "0.29.3"

View File

@@ -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 """

View File

@@ -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

View File

@@ -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",

View File

@@ -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"

View File

@@ -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",