1

I have a legacy Windows application which reads data from a database. One of the columns is 'TimeZoneInfoId'. Which in the legacy world was written by another windows application so it stores the Windows string: TimeZoneInfo.CurrentTimeZone.StandardName

I now need to write to this table from a Java application. So I'm trying to find a library that will map a time zone ID from the tz database (formerly known as the Olson database) to the windows timezone id. Ideally I'd like to use a library that in theory I could update to later releases in the future as I've read that timezone info can sometimes change.

I've searched a bit online already, and the answers I've found generally say either write your own mapping/lookup or use NodaTime and do the conversion in .NET (if you really need a library that can be updated).

I can't update the legacy code (wihtout a complete re-write) so just asking the question here since most of the answers I've found are a little old so maybe there is something new that I can avail of ;)

If not it will have to be a custom lookup function I hfea.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
procke
  • 75
  • 1
  • 7

1 Answers1

0

Well, assuming you meant the value came from TimeZoneInfo.Local.Id, then you can do this conversion. If it came from TimeZone.CurrentTimeZone.StandardName, then there will be some entries that fail because StandardName is a localized string, and the English form doesn't necessarily match the Id

Getting to your question, you could just look at the source XML data in CLDR, and parse it similar to how I described here.

Or, if you really want a library, consider that ICU4J has the methods getWindowsId and getIDForWindowsID that uses the same data to do the conversion. However, ICU can be really big, so if you only need it for this one thing then you might be better off going to the XML directly.

Community
  • 1
  • 1
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
  • Thanks! Some good info there. ICU4J looks to have exactly the method I need. But as you say, it's quite large for just this check. I think I'll try using the xml files - which can be updated in my source control, providing in essence the same fuctionality as upgrading a library :) – procke Apr 14 '16 at 12:10
  • Also worth mentioning: On Windows, Java does [keep it's own mappings](https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/time-zone002.html#CBBCCFCD), in `\lib\tzmappings`. However I'm uncertain if there's any API to expose this directly, or if it's available in non-Windows installations. It's there primarily for use when determining the system default time zone. – Matt Johnson-Pint Apr 14 '16 at 15:25