Skip to content

Replace S2 timezone handling from pytz to zoneinfo#192

Merged
Flix6x merged 2 commits intomainfrom
copilot/switch-to-zoneinfo-library
Apr 1, 2026
Merged

Replace S2 timezone handling from pytz to zoneinfo#192
Flix6x merged 2 commits intomainfrom
copilot/switch-to-zoneinfo-library

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 31, 2026

S2 modules were still relying on pytz (timezone() / localize()), which is legacy for modern Python timezone handling. This change migrates S2 timezone construction and aware datetime creation to stdlib zoneinfo.

  • Scope: S2 timezone migration

    • Replaced pytz imports/usages with zoneinfo.ZoneInfo in:
      • src/flexmeasures_client/s2/__init__.py
      • src/flexmeasures_client/s2/control_types/FRBC/frbc_simple.py
      • src/flexmeasures_client/s2/control_types/FRBC/frbc_tunes.py
      • src/flexmeasures_client/s2/script/websockets_client.py
  • Behavioral updates

    • Replaced timezone object creation:
      • pytz.timezone(name)ZoneInfo(name)
    • Replaced pytz.localize(...) pattern with native aware datetime construction:
      • datetime(..., tzinfo=ZoneInfo(...))
    • Updated FRBCSimple.now() to generate aware datetimes via:
      • datetime.now(self._timezone)
  • Focused coverage

    • Added tests/s2/test_timezone.py to assert S2 now() paths produce ZoneInfo-backed datetimes (Handler, FRBCSimple).
from datetime import datetime
from zoneinfo import ZoneInfo

tz = ZoneInfo("Europe/Amsterdam")
now = datetime.now(tz)
valid_from = datetime(2026, 1, 15, 20, tzinfo=tz)

Copilot AI changed the title [WIP] Replace pytz library with zoneinfo in s2 directory Replace S2 timezone handling from pytz to zoneinfo Mar 31, 2026
Copilot AI requested a review from nhoening March 31, 2026 12:53
@nhoening nhoening marked this pull request as ready for review March 31, 2026 12:57
Copy link
Copy Markdown
Contributor

@nhoening nhoening left a comment

Choose a reason for hiding this comment

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

I would like to leave it to @Flix6x to give this a final look.
I researched the only thing that gave me thought (see comment below).

@nhoening nhoening requested a review from Flix6x March 31, 2026 13:48
@nhoening nhoening added the S2 label Mar 31, 2026
@Flix6x Flix6x merged commit b6a1c5b into main Apr 1, 2026
10 checks passed
@Flix6x Flix6x deleted the copilot/switch-to-zoneinfo-library branch April 1, 2026 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants