ikvm icon indicating copy to clipboard operation
ikvm copied to clipboard

Replace Time Zone switch statement

Open wasabii opened this issue 2 years ago • 1 comments

This is the latest in a series of "lets try to do this better".

In the managed JNI backend for java.util.TimeZone, there exists a gigantic switch statement that maps values from TimeZoneInfo.Local.Id to ICANN (Olsen) format. This is because the .NET APIs that provide TimeZone information do not attempt to abstract by platform. On Windows they return Windows information. On Linux they return Linux information. Etc.

However, Java standardized on the Olsen format. Even on Windows. So, code needs to exist for IKVM to take what .NET thinks is the local time zone, no matter what platform, and return the same ID.

This switch statement was built form tzmappings. It should probably actually read from tzmappings on the fly.

wasabii avatar Jun 07 '22 04:06 wasabii

First of all, there is an open source project called TimeZoneConverter is being maintained to do this mapping prior to .NET 6.0.

For .NET 6.0+ this has now been fixed. That is, time zone ids can be looked up with either format now (since all of this is managed by ICU). So, we should set it up to use the built-in time zone conversions on .NET 6.0+ to ensure it is in sync with the version of ICU that is installed on the OS. ICU is included with every OS distribution and each one may ship with a different version of CLDR data.

Secondly, there is a gap between how time zones work in Java vs .NET. In Java, the time zone is set as a system property to the JVM. In .NET, the time zone is not settable at all, the TimeZoneInfo.Local property simply reads the time zone from the underlying OS and there is no way to set it.

Since this is a JVM implementation, we probably need to support setting as well as getting the time zone (I suspect that this is done already in the converted JDK), and it should also default to the time zone of the OS if the system property is not set (also probably happens, but it is probably worth a second look).

NightOwl888 avatar Jun 09 '22 00:06 NightOwl888