How to update TimeZone database for Swift on Linux

Hey,

I have been trying to get Swift on Linux use the most recent version of tzdata, but so far did not find any way to do so.

When using swift:5.9-jammy, this will have tzdata2023c-0 installed.

apt list --installed | grep tzdata
tzdata/now 2023c-0ubuntu0.22.04.2 all

when querying TimeZone.timeZoneDataVersion from Swift it will tell us it has Version 2019c

import Foundation

print(TimeZone.timeZoneDataVersion)  // "2019c"

Updating the system tzdata, does not solve any issues, but will eventually create even more problems, e.g. executing wget http://archive.ubuntu.com/ubuntu/pool/main/t/tzdata/tzdata_2023c-9ubuntu1_all.deb && sudo dpkg -i tzdata_2023c-9ubuntu1_all.deb && rm tzdata_2023c-9ubuntu1_all.deb will remove a symlink from /usr/share/zoneinfo/Europe/Kiev to /usr/share/zoneinfo/Europe/Kyiv. Therefore, after applying this TimeZone(identifier: "Europe/Kiev") and TimeZone(identifier: "Europe/Kyiv") will return nil, while TimeZone(identifier: "Europe/Kiev") was returning something valid before.

I understand that internally Swift Foundation uses ICU to query this data. However, I still don't fully understand when it depends on the system tzdata installation (obviously it somehow depends on it, because updating this data leads to changes) and when on the tzdata version that was used when building and linking against ICU.

Moreover, is there any way to update the time TimeZone.timeZoneDataVersion without recompiling Swift from scratch?

I doubt that. I haven't looked into it extensively but CoreFoundation hardcodes that tzdata directory directly, implying along with your Kiev example that it is looking there at runtime.

You can check this yourself by querying other tzdata that you know was updated.

Probably not, as that simply calls ucal_getTZDataVersion() from libicu, which as you noted probably just hard-codes the tzdata version at compile-time.

Thanks for your feedback!

That was also mostly what was confusing me. It seems Foundation TimeZone will respect updated files in /usr/share/zoneinfo, e.g. a country adopts or abolishes DST, correctly, but it will not allow any new identifiers to be added.

Still, why are the TimeZone.knownTimeZoneIdentifiers that should be coming from CFTimeZoneCopyKnownNames using __CFCopyRecursiveDirectoryList not affected by tzdata updates?

Is there any possibility this will change / be fixed with the new Foundation?