Skip to content

Datetime timezone awareness - #1590

Merged
JonnyWong16 merged 22 commits into
pushingkarmaorg:masterfrom
eliasbenb:feat/datetime-timezone-awareness
Mar 14, 2026
Merged

Datetime timezone awareness#1590
JonnyWong16 merged 22 commits into
pushingkarmaorg:masterfrom
eliasbenb:feat/datetime-timezone-awareness

Conversation

@eliasbenb

Copy link
Copy Markdown
Contributor

Description

Add optional timezone‑awareness for all parsed Plex datetime objects.

The PR introduces a plexapi.timezone config option (accepts bool or IANA time zone str). The configured time zone is parsed and globally defined. Subsequent calls to the utils.toDatetime() helper will normalize timestamps using that time zone.

Note: I've documented that "Toggling this option may break comparisons between aware and naive datetimes." Python's datetime does not support comparing naive and aware datetime objects (e.g. some_tz_aware_dt >= some_naive_dt will raise a TypeError).

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated the docstring for new or existing methods
  • I have added tests when applicable

@eliasbenb

Copy link
Copy Markdown
ContributorAuthor

Ready for review. I skimmed the codebase for from datetime.* imports and everything seemed to be covered by the new utils.toDatetime changes, but please let me know if you can think of other areas that may be inadvertently doing datetime parsing.

@eliasbenb
eliasbenb marked this pull request as ready for review February 28, 2026 14:03
CopilotAI review requested due to automatic review settings February 28, 2026 14:03

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an optional global timezone setting so plexapi.utils.toDatetime() can return timezone-aware datetime objects (driven by new plexapi.timezone config), with accompanying docs and tests.

Changes:

  • Introduces plexapi.utils.setDatetimeTimezone() + a global DATETIME_TIMEZONE used by toDatetime().
  • Initializes the timezone setting from config.ini during plexapi import.
  • Documents the new config option and adds tests for timezone-aware/naive behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
FileDescription
plexapi/utils.pyAdds timezone configuration + applies it in toDatetime() conversions.
plexapi/__init__.pyLoads plexapi.timezone from config and initializes global timezone behavior.
docs/configuration.rstDocuments the new timezone setting and its behavior/risks.
tests/test_utils.pyAdds unit tests for setDatetimeTimezone() and toDatetime() tz-awareness.
tests/test_video.pyAdds an integration-style test asserting media datetimes become aware/naive based on configuration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadplexapi/utils.py
Comment threadplexapi/utils.py
Comment threaddocs/configuration.rst
Comment threadtests/test_video.py Outdated
Comment threadplexapi/__init__.py Outdated
Comment threadplexapi/__init__.py Outdated

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadplexapi/utils.py Outdated
Comment threadplexapi/__init__.py Outdated
Comment threadplexapi/__init__.py Outdated
eliasbenband others added 4 commits February 28, 2026 09:48
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment threadplexapi/__init__.py Outdated
Comment threadplexapi/__init__.py Outdated
Comment threadplexapi/utils.py
Comment threadplexapi/utils.py
Comment threaddocs/configuration.rst
eliasbenband others added 3 commits March 11, 2026 20:02
Co-authored-by: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com>
Co-authored-by: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com>
Comment threadplexapi/__init__.py Outdated
Re-exporting `plexapi.utils.DATETIME_TIMEZONE` stores a copy of the string at import time, which can cause descync if setDatetimeTimezone is later called.
Instead, we should dynamically load the `DATETIME_TIMEZONE` reference in a module-level `__getattr__`
Comment threadplexapi/__init__.py

@JonnyWong16JonnyWong16 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks.

@JonnyWong16
JonnyWong16 merged commit e512ccd into pushingkarmaorg:masterMar 14, 2026
9 of 11 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@eliasbenb@JonnyWong16