Skip to content

refactor: replace usage of pytz with zoneinfo#475

Merged
asmfstatoil merged 4 commits into
mainfrom
replace_pytz
Jun 23, 2026
Merged

refactor: replace usage of pytz with zoneinfo#475
asmfstatoil merged 4 commits into
mainfrom
replace_pytz

Conversation

@asmfstatoil

Copy link
Copy Markdown
Collaborator

No description provided.

@asmfstatoil asmfstatoil changed the title refact: replace usage of pytz with zoneinfo refactor: replace usage of pytz with zoneinfo Jun 11, 2026
@asmfstatoil asmfstatoil requested a review from Copilot June 17, 2026 06:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors Tagreader’s timezone handling to remove the pytz dependency and use Python’s built-in zoneinfo instead, updating runtime code, tests, and documentation accordingly.

Changes:

  • Replaced pytz timezone usage with zoneinfo.ZoneInfo and datetime.timezone.utc in core code paths.
  • Updated tests to construct/compare timezone-aware datetimes using ZoneInfo, and refreshed docs/examples to use IANA zone names (e.g., America/Sao_Paulo).
  • Minor cleanup (tuple unpacking style, timedelta slicing simplification).

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tagreader/utils.py Switches default timezone handling to ZoneInfo and updates naive-datetime tz attachment logic.
tagreader/clients.py Updates client timezone parsing/validation to use ZoneInfo and removes pytz usage.
tagreader/web_handlers.py Replaces pytz.UTC conversions with datetime.timezone.utc.
tagreader/cache.py Replaces pytz.utc conversion with datetime.timezone.utc.
tests/test_utils.py Updates datetime-with-timezone assertions to use ZoneInfo.
tests/test_clients.py Updates timezone expectations to ZoneInfo.
tests/test_PIHandlerREST.py Minor tuple unpacking cleanup in tests.
tests/test_bucketcache.py Simplifies timestamp slicing using TS directly.
tests/test_AspenHandlerREST_connect.py Adjusts test time constants.
documentation/docs/about/usage/time-zone.md Updates timezone guidance from pytz to zoneinfo/tzdata.
documentation/docs/about/usage/basic-usage.md Updates example timezone string to America/Sao_Paulo.
docs/manual.md Updates manual to reflect zoneinfo usage and updated examples.

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

Comment thread tagreader/utils.py
Comment thread tagreader/clients.py Outdated
Comment thread tagreader/clients.py
Comment thread tests/test_utils.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

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 12 out of 13 changed files in this pull request and generated 2 comments.

Comment thread tagreader/utils.py
Comment on lines +55 to 59
if tz is None:
tz = ZoneInfo("Europe/Oslo")
date_stamp = convert_to_pydatetime(date_stamp)

if not date_stamp.tzinfo:
Comment thread tagreader/clients.py
Comment on lines +212 to +216
if tz is None or tz == "":
tz = ZoneInfo("Europe/Oslo")
if isinstance(tz, str):
if tz in pytz.all_timezones:
self.tz = pytz.timezone(tz)
else:
raise ValueError(f"Invalid timezone string Given type was {type(tz)}")
try:
self.tz = ZoneInfo(tz)
@asmfstatoil asmfstatoil merged commit a4ea28d into main Jun 23, 2026
13 checks passed
@asmfstatoil asmfstatoil deleted the replace_pytz branch June 23, 2026 22:27
Sign up for free to 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.

2 participants