Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Windows TimeZoneInfo from Latitude and Longitude

In a web app I have people enter their address, then I use Google's geocode API to get their latitude and longitude. Next, I would like to get their Windows time zone name using these coordinates so I can deal with Daylight Savings Time correctly via the .Net TimeZoneInfo object.

I played with several of the available time zone web services to get the time zone name such as:

  • http://www.askgeo.com/
  • http://www.geonames.org/
  • http://www.earthtools.org/

The issue is that these all return either just the offset from GMT, or the TZID (a.k.a. Olson) time zone name, not the Windows Time Zone name.

There is a listing at this following link that translates from Windows to TZID names, but not in the opposite direction since many of the TZID names are missing. For example, if the TZID I get from the first step is "Africa/Lusaka" then the table won't find an equivalent Windows Time Zone Name.

  • Windows -> TZID: http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/zone_tzid.html
  • TZID -> Windows: ???

So my question is, does anyone know of a service that can return a Windows Time Zone Name via lat/lon or if there is a complete listing or translation service to convert between the two naming formats?

Note: I have reviewed all the similar questions here, but none have completely solved this issue.

like image 359
CodeGrue Avatar asked Aug 16 '11 20:08

CodeGrue


1 Answers

One workaround would be to get the Olson name and then use Noda Time to perform the relevant time zone calculations, as that's based on the Olson names.

We're not quite "done" with Noda Time yet, but we're getting closer and closer to a 1.0 release - and you could always limit yourself to the time zone part if you wanted, and do the rest in .NET. That would isolate you from any areas we're still sorting out, such as formatting, parsing and the best API to expose for performing arithmetic. Admittedly I'd like to hope that the rest of the API appeals to you and entices you in... or that you'd want to comment on it and tell us how you'd want to use it :)

I'm hoping to add DateTime and DateTimeOffset conversions into the codebase in the next couple of days - if you can ping the mailing list with exactly what you need, I can try to accommodate you.

Apologies that this is only a workaround rather than a full fix. I will investigate providing more Windows zone name mapping information in Noda Time - that uses CLDR as well, but with more information from the Olson database, we may be able to find equivalents easily.

like image 167
Jon Skeet Avatar answered Oct 24 '22 09:10

Jon Skeet