Timezone databases #582
Replies: 5 comments 13 replies
-
|
Approach 1: |
Beta Was this translation helpful? Give feedback.
-
|
Approach 2: explicit |
Beta Was this translation helpful? Give feedback.
-
|
Approach 3: explicit |
Beta Was this translation helpful? Give feedback.
-
|
Approach 4: |
Beta Was this translation helpful? Give feedback.
-
|
Have you considered providing ~ There are multiple ways to approach this, but basically it would be configurable; it may fall back to System, xor it may throw when not configured. The main point is that the libs would, without a strong use case to do otherwise, use this tzdb source without any obstacles. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Timezone Database API
Currently,
kotlinx-datetimeonly allows using the system timezone database. There's an established practice in Android development to bundle timezone databases with the application so that older devices that no longer receive updates can also access up-to-date timezone information.(In this document, users are software developers that don't need to write their own timezone database implementations and don't publish their code as libraries.)
Figuring out the best API for this is challenging due to a tradeoff between convenience for users, flexibility in supporting niche use cases, and risks of using the API incorrectly. We have discussed several approaches that optimize for different aspects of usability, and we would like to receive input from the community to see which aspects you value the most.
There are four comments under this discussion, each with the name of one approach. Please upvote the comment with the approach of you like the most and downvote the comment with the approach you dislike the most. Also please leave any comments with concerns, suggestions, or use cases that come to mind.
Approach 1: ServiceLoader-style
Using the system timezone database: works as before.
Bundling the IANA timezone database: enabled by adding a runtime dependency on
kotlinx-datetime-zoneinfo.Using a custom timezone database: enabled by adding a runtime dependency on the library providing it.
The API for obtaining timezones stays the same as it is today:
Library code freely accesses timezones:
ofchecks which timezone databases the runtime classpath contains and chooses among them based on the priority specified by the authors of timezone database implementations.By default, a platform-specific timezone database is used: on the JVM, it's the timezone database provided by the JVM, on iOS, it reads the OS-level timezone database from the filesystem.
kotlinx-datetimewill start publishing a separate artifact that provides a timezone database implementation corresponding to the latest IANA version (https://www.iana.org/time-zones).The IANA timezone database is the timezone database that you are most likely already using; it's the one distributed with Android, iOS, MacOS, Linux, and used for .NET applications on Windows and the JVM.
Benefits of this approach:
TimeZoneDatabasein their API and can just write normal code.Downsides of this approach:
ServiceLoaderis not available for multiplatform Kotlin currently, it is a JVM-only mechanism, so different platforms require different non-obvious workarounds to emulate the same behavior.TimeZoneDatabaseimplementation needlessly, for example, by adding a runtime dependency on a timezone database implementation.Approach 2: explicit
interface TimeZoneDatabase, with no default common-code implementationUsing the system timezone database: the correct
TimeZoneDatabaseinstance must be manually used for each platform separately.TimeZone.ofand other singleton functions are not available.Bundling the IANA timezone database: a dependency on
kotlinx-datetime-zoneinfoprovides a newTimeZoneDatabaseimplementation, which must be manually used.Using a custom timezone database: the corresponding
TimeZoneDatabaseimplementation must be manually used.There is no
TimeZone.of, and the only way to obtain a timezone is to use a timezone database, which is passed explicitly.There is no singleton like
TimeZoneDatabase.System. Instead, on the JVM, there would beTimeZoneDatabase.Jvm, on iOS,TimeZoneDatabase.FilesystemandTimeZoneDatabase.Foundation, and on Windows,TimeZoneDatabase.Registry(names are not final and are just examples).There is also a common-code
TimeZoneDatabase.Ianapublished in a separate artifact that needs to be used manually if one wants a timezone database implementation that's guaranteed to be up-to-date.Benefits:
TimeZoneDatabaseinstances, which means that usages ofTimeZoneDatabaseare made transparent.Downsides:
Approach 3: explicit
interface TimeZoneDatabasewith a non-overridableTimeZoneDatabase.SystemUsing the system timezone database: the
TimeZoneDatabase.Systeminstance must be manually used.TimeZone.ofand other singleton functions are not available.Bundling the IANA timezone database: a dependency on
kotlinx-datetime-zoneinfoprovides a newTimeZoneDatabaseimplementation, which must be manually used.Using a custom timezone database: the corresponding
TimeZoneDatabaseimplementation must be manually used.This is similar to the previous approach, but there is
TimeZoneDatabase.Systemin common code.It always refers to the system timezone database, even if
TimeZoneDatabase.Ianais available.Benefits:
TimeZoneDatabase.Systemin user code.Downsides:
TimeZoneDatabasein their APIs, which defeats the purpose ofTimeZoneDatabase.Ianaand other custom timezone databases.Approach 4:
interface TimeZoneDatabasewithTimeZoneDatabase.Systemoverridable only byIanaUsing the system timezone database: the
TimeZoneDatabase.Systeminstance must be manually used.TimeZone.ofand other singleton functions are not available.Bundling the IANA timezone database: using the
TimeZoneDatabase.Systemautomatically delegates to the IANA timezone database if there's a runtime dependency onkotlinx-datetime-zoneinfo.Using a custom timezone database: the corresponding
TimeZoneDatabaseimplementation must be manually used.A combination of approaches 3 and 1.
If
TimeZoneDatabase.Ianais present,Systemwill default to using it via aServiceLoader-like mechanism.Benefits:
Systemwith a more up-to-dateIanatimezone database is covered without any extra boilerplate.TimeZoneDatabase.System, the right thing will still happen ifIanais available.Downsides:
ServiceLoader-based approach, they are treated as equals.Beta Was this translation helpful? Give feedback.
All reactions