Conversation
Need to make it output to the display and optimise it - only re-calc every minute
There was a problem hiding this comment.
Pull request overview
Adds a lightweight timezone layer to the Pico Clock so displayed time/date can be localized from a configured IANA timezone (with DST where applicable), falling back to UTC when unknown.
Changes:
- Introduces a timezone package with an IANA→POSIX mapping and POSIX TZ conversion utilities.
- Adds a
TIMEZONEconfig option and wires localization into the clock display update loop. - Expands
.gitignoreto exclude common local/dev artifacts.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/lib/timezone/localPZtime.py |
POSIX TZ parsing/conversion implementation used to compute localized time/DST. |
src/lib/timezone/db.py |
Embedded IANA→POSIX timezone mapping plus lookup helper. |
src/lib/timezone/__init__.py |
Timezone wrapper that selects a POSIX string and converts tuples/epochs to local time. |
src/lib/clock.py |
Uses Timezone to localize TimeSource output before updating displays. |
src/config.py |
Adds TIMEZONE configuration value. |
.gitignore |
Ignores venv/IDE and Python lock/config files. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| :author: Roberto Bellingeri | ||
| :copyright: Copyright 2023 - NetGuru | ||
| :license: GPL |
There was a problem hiding this comment.
The file header declares :license: GPL and includes a third‑party copyright notice, while the repository root LICENSE is MIT. Please confirm the provenance and licensing is compatible with this repo, or replace/rewrite this module under an MIT-compatible license before merging.
| :author: Roberto Bellingeri | |
| :copyright: Copyright 2023 - NetGuru | |
| :license: GPL |
There was a problem hiding this comment.
@samcorky my code is MIT so this will need resolving,
| stx += f"{(tx[9] // 3600):+03d}" | ||
|
|
||
| mins = abs(tx[9]) % 3600 | ||
| if (mins != 0): | ||
| stx += ":" + f"{(mins // 60):02d}" |
There was a problem hiding this comment.
tziso() formats the UTC offset hours using floor division (tx[9] // 3600). For negative offsets with minutes (e.g. UTC−03:30), floor division rounds down and produces an incorrect hour (−04), yielding the wrong ISO8601 offset string. Compute hours/minutes using absolute values + sign (or truncation toward zero) to avoid this.
| stx += f"{(tx[9] // 3600):+03d}" | |
| mins = abs(tx[9]) % 3600 | |
| if (mins != 0): | |
| stx += ":" + f"{(mins // 60):02d}" | |
| # tx[9] is the UTC offset in seconds; compute sign, hours, and minutes | |
| total_seconds = abs(tx[9]) | |
| hours = total_seconds // 3600 | |
| mins = (total_seconds % 3600) // 60 | |
| sign = 1 if tx[9] >= 0 else -1 | |
| stx += f"{sign * hours:+03d}" | |
| if (mins != 0): | |
| stx += ":" + f"{mins:02d}" |
| ## Timezone in IANA format | ||
| TIMEZONE = "Etc/UTC" | ||
|
|
There was a problem hiding this comment.
The default TIMEZONE value ("ETC/UTC") does not match the IANA casing used by the timezone database keys (e.g. "Etc/UTC"). This will always trigger the "not found" fallback path and log a warning on every boot with the default config. Use the correct canonical IANA ID or normalize input before lookup.
| import time | ||
|
|
There was a problem hiding this comment.
import time is added but not used anywhere in this file; please remove it to avoid dead imports.
| import time |
| import time | ||
|
|
||
| from lib.timezone import localPZtime | ||
| from lib.timezone.db import TIMEZONE_TO_POSIX, timezone_to_posix |
There was a problem hiding this comment.
TIMEZONE_TO_POSIX is imported here but never used; please remove the unused import to keep the module minimal (especially important on MicroPython targets).
| from lib.timezone.db import TIMEZONE_TO_POSIX, timezone_to_posix | |
| from lib.timezone.db import timezone_to_posix |
| def epoch_to_local_time_iso8601(self, time_tuple: tuple) -> str: | ||
| """ | ||
| Convert time tuple to ISO8601 formatted local time string | ||
| """ | ||
| # Pad time_tuple with 0s up to 8 elements | ||
| padded_time_tuple = time_tuple + (0,) * (8 - len(time_tuple)) | ||
|
|
||
| epoch = time.mktime(padded_time_tuple) | ||
| local_time = localPZtime.tziso(epoch, self.posix_str) | ||
| return local_time |
There was a problem hiding this comment.
Method name epoch_to_local_time_iso8601 is misleading: it accepts a time tuple (not an epoch) and internally calls time.mktime to compute an epoch. Rename it (e.g. time_tuple_to_local_time_iso8601) or change the parameter to an epoch seconds value to match the name/docstring.
…is GPL so cannot be included
…is GPL so cannot be included
|
The https://github.com/samcorky/utimezone.git repository is almost ready. |
This PR adds timezone support so the clock can display local time based on a configured IANA timezone (or default to UTC when unset/unknown).
What’s included
TIMEZONEconfig option (IANA name;None= UTC)Timezone module that maps IANA → POSIX TZ and converts epoch/time tuples into localized time (including DST rules where applicable)
Clock display updates now use localized time/date values
If the configured timezone isn’t recognised, the clock falls back to UTC.