Skip to content

OnlyCatAI/utz

 
 

Repository files navigation

μ time zone (library)

An embedded timezone library and ~3kB tzinfo database featuring nearly all current timezones present in the IANA timezone database. Designed for use on budget embedded systems with low program space.

The C header containing packed timezone information is generated from the IANA timezone database.

Tradeoffs

All historical timezone information has been pruned to save space.

The generated lookup table contains every name in whitelist.txt, including both direct IANA zones and aliases. Generation fails if a whitelisted name cannot be resolved, so the whitelist is also the public compatibility list.

This library is generally inflexible as it heavily relies on assumptions pertaining to timezone offset increments, abbreviation formatting, etc to make efficient use of bit packs.

Limitations

The current utility library does not support parsing / packing all possible syntax of the source IANA tz database. Instead a subset corresponding to the what is needed to correctly parse most zones is implemented.

Links

zic man page and IANA tz database format documentation

vendored files

Instructions to generate files (without Make)

  1. Setup dev environment: python3 -m pip install -r requirements.txt
  2. Generate links based on major cities: python3 utils/compile_tzlinks.py
  3. Generate a list of timezones to include, based on major cities and timezones included in Android: python3 utils/compile_whitelist.py
  4. Generate zones.h and zones.c: python3 utils/generate_zones.py -d vendor/tzdata -r africa -r asia -r australasia -r backward -r europe -r northamerica -r southamerica -r etcetera -w whitelist.txt -i majorcities

Include different regions in step 4 based on your preferences.

Run make test to compile with warnings enabled, verify that the generated lookup names exactly match the whitelist, and exercise fixed-offset and DST transition behaviour. The test intentionally runs under a non-UTC process timezone to ensure calculations depend only on their UTC timestamp.

OnlyCat fork

This fork retains full IANA identifiers in the generated lookup table. It also ports applicable correctness work from flipperdevices/utz, notably direct whitelist support, normalized negative fractional offsets, strict compiler checks, and transition regression tests, while preserving the existing time_t API.

Updating the TZ Database

To update the tzdatabase replace the files in vendor/tzdata with that of the following link: https://www.iana.org/time-zones Use the data only distribution

The database is currently pinned to 2023c. Before updating it, check for future base-offset transitions: the packed format supports recurring daylight-saving rules but cannot represent a Zone whose standard UTC offset changes after the firmware is built. IANA 2026c contains such a transition for Africa/Casablanca in September 2026.

Should make this an automatic process via GitHub actions (Possible Feature).

About

A Time Zone Library for Tiny Embedded Systems - Last Updated November 2023!

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • C 68.6%
  • Python 29.8%
  • Makefile 1.6%