Olson timezone identifier to standard Windows format using Noda Time

The conversion between Olson's time identifier and Windows has appeared many times on SO; with many people offering Jon Skeet Noda Time for this task.

As long as the Google Code page states that there is a function for converting between the two, I cannot find any details anywhere on how to do this.

Can someone point me in the right direction?

+4
source share
2 answers

No, unfortunately, at the moment we do not have a mapping (Windows to Olson).

The entire "provider" interface is right in the air right now:

  • Even in the current code, there are API changes we want to make, partly to make the code more robust
  • Unicode CLDR mappings have changed between 1.x and 2.x, so now there are several mappings each, potentially (IIRC).

In other words: sorry, we do not support this at the moment, but we will keep this in mind when we try to shut down API 1.0.

+1
source

TzdbTimeZoneProvider supports conversion from Windows to Olson, but BclTimeZoneProvider (a provider for Windows time zones) does not have the correct MapTimeZoneId method MapTimeZoneId and the interface seems to be wrong ...

Here is the implementation on TzdbTimeZoneProvider :

  public string MapTimeZoneId(TimeZoneInfo zone) { string str; this.windowsIdMap.TryGetValue(zone.Id, out str); return str; } 

Note: windowsIdMap is a dictionary

Here is the implementation on BclTimeZoneProvider :

 public string MapTimeZoneId(TimeZoneInfo timeZone) { return timeZone.Id; } 

Note. It simply returns the identifier of the Windows temporary window.

It seems that a more proper interface for this method would be:

  string MapTimeZoneId(string providerZoneId); 

Then both implementations can be performed correctly. I think you can ask this question in Google Noda Time groups.

Now you can look at TzdbTimeZoneProvider to find a way to map from Olson to Windows tz (a simple iteration through windowsIdMap values).

0
source

Source: https://habr.com/ru/post/1392222/


All Articles