Skip to content

Commit

Permalink
Feature original date 1625 (#1729)
Browse files Browse the repository at this point in the history
* Add date to ExifInfo

* Fix test for timezone

* Added photos_datetime_local

* Converted albuminfo to new datetime methods

* Converted comments/likes to new datetime methods

* Converted comments/likes to new datetime methods

* Converted iPhoto code to new date methods

* Converted iPhoto code to new date methods

* Refactored date code in ShareInfo

* added .workingon

* Refactored date code in FingerprintQuery, added tests

* Fix test for linux

* Refactored PhotosDB date code, updated tests

* Added date_original

* Test updates

* test updates

* test updates

* More test fixes

* Test updates

* Test updates

* Removed dt_to_local

* Removed dt_to_local

* Initial reset implementation

* First commit

* Fixed timezone handling for --parse-date

* All timezone tests passing

* Automated timewarp tests, added --uuid

* Added test for timewarp --reset

* Updated API readmen

* Updated date methods to use named timezone instead of offset

* Updated help for --reset

* Moved timewarp code to timewarp_cli so it can be called independently of the CLI

* Updated help text for --timezone
  • Loading branch information
RhetTbull authored Oct 30, 2024
1 parent 2bedf53 commit 685b715
Show file tree
Hide file tree
Showing 148 changed files with 2,407 additions and 380 deletions.
24 changes: 18 additions & 6 deletions API_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -993,22 +993,34 @@ Returns the original filename of the photo when it was imported to Photos. **No

#### `date`

Returns the create date of the photo as a datetime.datetime object
Returns the create date of the photo as a timezone aware datetime.datetime object

#### `tzoffset`

Returns the timezone offset from UTC in seconds for the Photo creation date

#### `tzname`

Returns the timezone name for the Photos creation date; on Photos version < 5, returns None

#### `date_original`

Returns the original creation date of the photo as a datetime.datetime object.
Returns the original creation date of the photo as a timezone aware datetime.datetime object.
If user changed the photo's date in Photos, this will return the original date Photos assigned
as the creation date at the time of import.
as the creation date at the time of import. The original date is stored by Photos at import time
from the date in the photo's EXIF data. If this is not set (photo had no EXIF date or photo was
imported on an older version of macOS that did not store original date) then `date_original`
returns the same value as `date`.

Photos 5+ only; on Photos < 5.0, this will return the same value as `date`.

#### `date_added`

Returns the date the photo was added to the Photos library as a timezone aware datetime.datetime object, or None if the data added cannot be determined
Returns the date the photo was added to the Photos library as a timezone aware datetime.datetime object in the local timezone, or None if the data added cannot be determined

#### `date_modified`

Returns the modification date of the photo as a datetime.datetime object or None if photo has no modification date
Returns the modification date of the photo as a timezone aware atetime.datetime object in the local timezone or None if photo has no modification date

#### `description`

Expand Down Expand Up @@ -1164,7 +1176,7 @@ Returns `True` if the picture is in the trash ('Recently Deleted' folder), other

#### `date_trashed`

Returns the date the photo was placed in the trash as a datetime.datetime object or None if photo is not in the trash
Returns the date the photo was placed in the trash as a timezone aware datetime.datetime object in the local timezone or None if photo is not in the trash

#### `location`

Expand Down
2 changes: 1 addition & 1 deletion osxphotos/cli/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,7 @@ def export_cli(
locals_,
ignore=["ctx", "cli_obj", "dest", "load_config", "save_config", "config_only"],
)

print(f"{locals_=} {cfg=}")
verbose = verbose_print(verbose=verbose_flag, timestamp=timestamp, theme=theme)

if load_config:
Expand Down
22 changes: 13 additions & 9 deletions osxphotos/cli/param_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"TimeISO8601",
"TimeOffset",
"TimeString",
"UTCOffset",
"TimezoneOffset",
]


Expand Down Expand Up @@ -299,20 +299,24 @@ def convert(self, value, param, ctx):
)


class UTCOffset(click.ParamType):
"""A UTC offset timezone in format ±[hh]:[mm], ±[h]:[mm], or ±[hh][mm]"""
class TimezoneOffset(click.ParamType):
"""A UTC offset timezone in format ±[hh]:[mm], ±[h]:[mm], or ±[hh][mm] or a named timezone such as "America/Los_Angeles" """

name = "UTC_OFFSET"
name = "TIMEZONE_OFFSET"

def convert(self, value, param, ctx):
try:
offset_seconds = utc_offset_string_to_seconds(value)
return Timezone(offset_seconds)
except Exception:
self.fail(
f"Invalid timezone format: {value}. "
"Valid format for timezone offset: '±HH:MM', '±H:MM', or '±HHMM'"
)
except ValueError as e:
try:
# might be named timezone
return Timezone(value)
except ValueError as e:
self.fail(
f"Invalid timezone format or name: {value}. "
"Valid format for timezone offset: '±HH:MM', '±H:MM', or '±HHMM' or named timezone such as 'America/Los_Angeles'"
)


class StrpDateTimePattern(click.ParamType):
Expand Down
Loading

0 comments on commit 685b715

Please sign in to comment.