3

Currently I'm using NodaTime to get the time zone from country but the problem is if there are multiple time zones in a country. How could I know the list of the cities in that time zone? I need to know do the mapping between these two data. Is it possible with NodaTime?

user702160
  • 113
  • 1
  • 4
  • I imaging that Noda supports times in the USA so it would expect it would be possible. Have a look at http://msdn.microsoft.com/en-us/magazine/jj991981.aspx and search for America/Vancouver to see an example. – simon at rcl Feb 05 '14 at 18:00
  • 2
    Your question doesn't make much sense. Noda Time doesn't let you get *the* time zone for a country, only for a time zone identifier, such as a IANA (tzdb) zone of "America/Los_Angeles" or a Windows (bcl) zone of "Pacific Standard Time". You could filter the list of available zones by country, sure. Is that what you are trying to do? If so, see the function I wrote [in this answer](http://stackoverflow.com/a/17098904/634824). – Matt Johnson-Pint Feb 06 '14 at 05:58
  • @MattJohnson Sorry for lately reply. Actually, I mapped the country by looping through TzdbDateTimeZoneSource.Default.ZoneLocations then I get time zone by mapping by checking if TzdbDateTimeZoneSource.Default.WindowsMapping.MapZones contains TzdbDateTimeZoneSource.Default.ZoneLocations(i).ZoneId. But my current problem is I would like to find the time zone of departure and arrival cities. That's why I would like to know how can I track that which city is on which time zone. – user702160 Feb 07 '14 at 10:44

1 Answers1

3

The correct way to handle this is as follows:

  • Find latitude and longitude for each location. If these are airports, then consider using the data from OurAirports.com. You might also be interested in OpenFlights, but be aware that they source their data from OurAirports.com anyway. And while OpenFlights data has some time zone information, it's not accurate enough to map to a true IANA time zone identifier.

  • Once you have longitude and latitude, then you can use one of these methods to lookup the time zone from the location.

  • Then you can pass that time zone identifier to NodaTime via DateTimeZoneProviders.Tzdb[theTimeZoneId]

Community
  • 1
  • 1
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
  • As a side note I am currently working on a library called [GeoTimeZone](https://github.com/mj1856/GeoTimeZone) that will do the lat/lon to timezone lookup in a single dll as a portable class library. It is not quite ready for consumption, but when available then it would be an ideal choice to pair with Noda Time for timezone lookup from lat/lon. Perhaps after that is complete I will create a companion library that includes the airport data. – Matt Johnson-Pint Feb 07 '14 at 16:38
  • Just an update - [GeoTimeZone](https://github.com/mj1856/GeoTimeZone) is good enough to use for this purpose now. – Matt Johnson-Pint May 12 '15 at 20:00
  • Proof of concept and output are [here](https://gist.github.com/mj1856/6d219c48697c550c2476) – Matt Johnson-Pint May 12 '15 at 20:40