Add parsing for TZif v2+ (tzdata2 APEX) on Android #5235
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Starting with Android 11, the platform ships its time-zone package as
com.google.android.tzdata2
, whose files use the TZif v2/v3 specification (RFC 8536) with 64-bit transition timestamps (Google also introduced a new APEX-based mechanism for updating time zones on all Android 10+ devices)https://source.android.com/docs/core/ota/modular-system/timezone
CFTimeZone.c
currently only understands v1 layout, so CoreFoundation on Android silently falls back to “GMT” for any device that only contains the new formatWhat this patch does
struct tzhead
to include the one-byteversion
field__CFDetzcode64
to decode 64-bit big-endian integers safely (no UB on signed shifts)version
, and settrans_size
to4
(v1) or8
(v2+)version > 1
, skip the v1 data block and read the second header that precedes the 64-bit sectiontrans_size
consistently when advancing the transition and type pointersTesting
This patch affects CFTimeZone in CoreFoundation only. It does not affect Foundation.TimeZone, which continues to use ICU-based time zone data:
I wrote a test case verifying the recent time zone change in Asia/Almaty, where Kazakhstan unified to UTC+5 in March 2024. However, I didn't commit it, as it would fail on all platforms using older tzdata (e.g. ICU 2023c).
Result on Android with tzdata 2025b
❌ Foundation.TimeZone still returns outdated UTC+6 due to bundled ICU 2023c
✅ CFTimeZone reports correct offset (UTC+5)
Next steps
Explore how to make Foundation.TimeZone use the system-provided tzdata on Android. Currently, it relies on ICU's bundled data, which may be outdated compared to the APEX module. Aligning both would ensure consistent and up-to-date time zone behavior across the system.