Tiny helpers for IANA time zones and abbreviations
Project description
tznn
Tiny helper for IANA time zones and abbreviations.
This package provides a small utility class backed by a static mapping in timezone.json to:
- List available IANA time zone names
- Look up the time zone abbreviation (e.g., SGT, EDT) for a given zone
Notes:
- Abbreviations are static values from
timezone.jsonand are not date-aware (no DST transitions). - On Windows,
tzdatais listed as a dependency in case you choose to extend functionality using IANA tzdata; the current implementation only readstimezone.jsonand does not require system tzdata at runtime.
Install
From the project root:
pip install .
For development (tests, etc.):
pip install -r requirements.txt
Quick start
from tznn import tznn
tz = tznn()
# 1) Get a sorted list of available IANA time zone names
zones = tz.get_available_time_zones()
print(len(zones), zones[:5])
# 2) Get the abbreviation for a known time zone
print(tz.get_abbr("Asia/Singapore")) # -> "SGT"
print(tz.get_abbr("America/New_York")) # -> e.g., "EDT" per timezone.json
# 3) Get the full mapping of zone -> abbreviation
mapping = tz.get_all_available_time_zones()
print(mapping["America/New_York"]) # -> "EDT"
Why use this package?
Default Python libraries do not provide a simple way to get static time zone abbreviations from IANA zone names. This package fills that gap with a lightweight solution. Example :
from datetime import datetime
from zoneinfo import ZoneInfo
dt_utc = datetime(2025, 9, 23, 3, 2, 7)
dt_vn = dt_utc.astimezone(ZoneInfo("Asia/Ho_Chi_Minh"))
print(dt_vn.strftime("%d/%m/%Y %H:%M:%S %Z %z")) # → 23/09/2025 10:02:07 ICT +0700
The result is 23/09/2025 02:02:07 +07 +0700 but expectation should be 23/09/2025 10:02:07 ICT +0700
API
Class: tznn
-
get_available_time_zones() -> list[str]- Returns a sorted list of all IANA zone names present in
timezone.json.
- Returns a sorted list of all IANA zone names present in
-
get_all_available_time_zones() -> dict[str, str]- Returns the entire mapping of
zone_name -> abbreviationloaded fromtimezone.json.
- Returns the entire mapping of
-
get_abbr(tz_name: str) -> str- Returns the abbreviation for the given IANA time zone name.
- Raises
ValueErrorif the zone name is not found in the mapping.
Data source and limitations
- Data is loaded from the local
timezone.jsonfile included in the repository. - Abbreviations are static and may not reflect historical or future DST changes. If you need date-aware abbreviations,
consider using Python's
zoneinfomodule (Python 3.9+) together with an appropriate tz database.
Testing
Run the test suite from the project root:
pytest -q
The tests validate:
- The list of available zones is sorted and non-empty.
- The mapping includes known zones and string abbreviations.
get_abbrreturns correct abbreviations and raises on invalid zones.
Roadmap (ideas)
- Optional date-aware abbreviation lookup using
zoneinfo(orpytzfor older Pythons). - Utilities for DST-aware conversions and current time by zone.
Knowledge
- https://adamj.eu/tech/2021/05/06/how-to-list-all-timezones-in-python/
- https://stackoverflow.com/questions/78580391/zoneinfo-is-missing-timezone-names-that-pytz-has
- https://docs.python.org/3/library/zoneinfo.html
- https://github.com/python/tzdata/issues/111
- https://discuss.python.org/t/get-local-time-zone/4169/10
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tznn-0.1.0.tar.gz.
File metadata
- Download URL: tznn-0.1.0.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40ee04f5baf50de3b2c22847d66fe91c19ab48119a6f0029acaa11113742665f
|
|
| MD5 |
5d1a47cefd483c9974dd52568d777ada
|
|
| BLAKE2b-256 |
061d74b30418796c0a52ede18b45975ae506705b4fa4103506ad2ccc5e73a7b3
|
File details
Details for the file tznn-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tznn-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0424d82f5b13d084d11497a13df9337218490ff62ce4b2e30a1f9c7118784f0
|
|
| MD5 |
e0ada9f41af3e3a2dd9a891623e38b83
|
|
| BLAKE2b-256 |
bfeacd6581aec3583c4ddd809548ecae8dad664b90622e67d547d60ca56c6f4b
|