Looking up timezone from region / coordinates - timezone

I would like to look up a timezone based on an ISO region code or coordinates.
I have a collection of data points with coordinates, county and region codes, eg:
33.942501,-118.407997,"US","US-CA"
I want to find the IANA timezone identifier, eg. America/Los_Angeles, based on the above info.
Is it possible to do that with NodaTime? I cannot see a way to look up DateTimeZone or timezone identifier from a region code or location.

The GeoTimeZone NuGet package can provide a lookup by lat/long to IANA ID, and then you can use DateTimeZoneProviders.Tzdb[id] to get the DateTimeZone from that. See the project home page for more details.
Within Noda Time itself, you can use TzdbDateTimeZoneSource.Default (or one that you've loaded) and then the ZoneLocations or Zone1970Locations properties to find zones for specific ISO-3166 countries... but they doesn't go below the "country" level (although they do have exemplar lat/long values). They're based on zone.tab and zone1970.tab - so any information not in that file isn't present in Noda Time either.
It sounds like GeoTimeZone is probably your best option here.

Related

Querying by timezone vs location

Moment-timezone time has method momnet.tz that takes two params:
particular datetime
timezone name
It returns time shift (to UTC) that was at given timezone in given datetime. Ok.
The question that bothers me:
do all the locations that currently belong to a particular timezone were in the past belonging to that zone also?
so isn't it possible that if two locations even currently belonging to a certain timezone, in the past (even after 1970) had actually different timezones (shifts to UTC).
Is it possible in principle to query tz-db for specific some kind of location, not a timezone name.
Would be grateful if someone could eliminate my doubts.
Moment-timezone uses the data from the IANA time zone database (aka the TZDB, zoneinfo, or the Olson database). Most of your questions are addressed by that data, rather than by moment-timezone itself. You'll find that other implementations (for other languages, platforms, etc.) have similar behaviors.
There is a great deal of information about how the tzdb works in the theory file in the tzdb itself, and on Wikipedia, but I'll see if I can address your specific questions:
do all the locations that currently belong to a particular timezone were in the past belonging to that zone also?
The TZDB assigns time zones based on cities (because they are less likely to changes over time than other regional boundaries). Generally, one city within a given region whose clocks have been aligned since 1970 will be chosen to represent the time in that region.
When another part of that region changes their clocks differently than the rest of the region, a new time zone is created and a new city is chosen within that region to represent the zone. We call this a "zone split". Time before the split in both zones will match (except the LMT entry), and time at the split and forward will deviate. It doesn't matter if at some point in the future the time in these regions aligns again. There are now two zones and there will continue to be - because they deviated at some point in the past.
so isn't it possible that if two locations even currently belonging to a certain timezone, in the past (even after 1970) had actually different timezones (shifts to UTC).
If there is a distinct history of timekeeping in the region, then there will be two different time zone entries. So when you say "locations", if you mean two different cities with their own time zone names in the TZDB, then by definition they don't belong to the same time zone. For example, Europe/Moscow and Europe/Volgograd are both currently in UTC+3 year-round without DST. However at the start of 1992, Moscow was UTC+3 while Volgograd was UTC+4. Their histories before then deviate even further.
On the other hand, if you are talking about a location that is not specifically referenced in the TZDB, then there is a presumption of alignment. For example, Seattle is in the US Pacific time zone, all of which is represented by America/Los_Angeles. Because there is not a unique America/Seattle, the data is representing that Seattle does not have a unique time zone history than Los Angeles.
That said - there have been a few very minor edge cases that have come up in the past where a small town that is on the boundary line between two time zones has to chose between which zone to observe. It has also happened that a small town distinctly on one side of the boundary has chosen to unofficially follow the time zone in a neighboring larger city on the other side of a boundary. These changes are sometimes mentioned on the tzdb discussion list, but are rarely recorded in the data as a distinct zone.
With these edge cases, keep in mind that the TZDB only tracks cities - not regional boundaries that may divide cities or towns. For that, you'd have to go different data source. The best one I know of is Evan Siroky's timezone-boundary-builder project.
Is it possible in principle to query tz-db for specific some kind of location, not a timezone name.
You'll have to be more specific about what you mean by "location". If you mean a latitude/longitude coordinates - then the timezone-boundary-builder data, and the projects that use them, are the route to go. They will help you resolve a tzdb identifier, which you can then use with moment-timezone or other libraries.

How to capture city name

Is there an accurate way to capture the city/town/village of a user without having them mention it.The gps co ordinates only give you the distance from a specific spot.
According you have a database (from geoname or whatever open or private sources you can easily find on internet) or use an api (like api.geoname.org), you can locate in which village is the coordinate and then find the town, then the country ...

Is there a site that allows timezone conversion on a given date easily by URL

I am looking for a timezone converter site which accepts arguments of a time, city, and date on the command line and opens up a page showing the equivalent time/date in my current locale. (Needing to specify my current locale would be acceptable.) I do need it to be a little smart about searching for the cities - I don't want to have to enter an exact timezone syntax but rather a substring which results in a unique search.
Unfortunately spending money is not an option - I've got to find a free service.
More detail:
I use DTRT extensively and would love to be able to do an instant time zone conversion straight from my address bar.
I would like to type this:
3pm Dallas 2015-03-20
and get a page telling me what time that will be in my current location (and perhaps in certain other locations I would set up).
The DTRT is designed to simply convert the query string in the URL to a different URL so I'm looking for a site that might accept GET parameters like this in the URL. I've done quite a bit of googling, but so far everything I have found either (1) requires me to go through their interface to convert the cities to codes or (2) doesn't do GET parameters at all.
Any time zone converters you know that do this? The closest I've found is this and it uses those codes...
Here is another option which works just by naming the city in the URL, but it has no capability of doing it for another date. When I am setting up meetings when one city changes to DST one week and another city 3 weeks later I absolutely have to have the date capability.
Have you tried wolfram alpha?
https://www.wolframalpha.com/input/?i=3pm+Dallas+2015-03-20

How do I get the utc offset from an address?

I have a RoR application where I store locations using gmaps4rails. Based on the address of the location, I'd like to guess the UTC offset ("+00:00", "-05:00", ..).
Is it possible or I have to ask users (and trust them) to set the correct timezone offset?
By the way, I know that there are some places where the timezone offset may change during the year. In this case, I should use the zone name instead of the offset. Is there a gem that helps to deal with these issues?
Thank you,
Geolocate the address to lat/lon coordinates using any number of web services for this. Then see the options in How to get a time zone from a location using latitude and longitude coordinates? The Ruby gem that Yevgeniy mentioned is listed there, along with other options.
Don't try to get an offset for the location - it could change periodically for DST. Get the time zone instead, such as Asia/Singapore or America/New_York. Then use that to determine the offset for a particular point in time.
See "Time Zone != Offset" in the timezone tag wiki.
Even if you get the solution, it is better to ask them from user. If user in the US wants to see his/her datetime according to timezone in Singapore (because that is his/her homeown), he/she should be shown it like that.

Lookup telephone area code by latitude and longitude

Looking for a way to get a list of telephone area codes for a given latitude and longitude (and if necessary a given intl. code.) Note, I'm not talking about international dialing prefixes but the area codes within them.
For example, Denver Colorado is covered by the area codes 303 and 720. It's at 39.739 -104.985 and is in NANP 1. So given 39.739,-104.985,1 I'd like to get back [303,720].
Libraries, web services, DB's, or raw data that needs to be parsed into a DB, e.g., a web page of shape points, are all fine and the more global coverage the better, but just NANP 1 would be a great help.
Note I already use MaxMind and could turn the lat-lng into a fake IP and use that as the lookup key, but MaxMind claims only U.S. area codes (whether they truly mean U.S. or actually NANP I haven't tested) and seemingly only 1 per location (e.g. just 303 for Denver.) So it's a possibility, just not a great one.
UPDATE: I found some more relevant information, but no definitive solutions so I'm listing it here rather than in an answer:
I was able to find two U.S. databases http://www.area-codes.com/area-code-database.asp and http://www.nationalnanpa.com/area_codes/index.html (50% down the page, MS Access file.) The former includes lat/lng for $450 and the latter would require nearest-neighbor matching as KeithS talks about (it's probably the same DB underlying the NANPA City Query he found.)
Additionally I found information that implies Teleatlas has area code boundary maps and that ESRI includes area code shape files with copies of ArcGIS. Maponics seems to have data available: there's a Google Maps implementation of Maponics' data at http://www.usnaviguide.com/areacode.htm.
Wow. You'll definitely need some sort of pre-existing database of points. My first thought was ZIPList5 Geocode. It includes lat-long data for each active U.S. ZIP code, so you can throw this data in a DB table, index the hell out of it, and search by just about any geographic info you'd have access to. You can buy one copy for $40, with enterprise-level use for $100. Only problem is that this DB has only the "primary" area code for each ZIP code, so metro areas that have more than one (Dallas, Chicago, NYC) aren't going to show all of them.
You could try a two-pronged approach with some free data I found: for a given latitude and longitude, do a nearest-neighbors search of the data in the USGS Geographic Names Information System; it includes information on every human habitation center, and every named landmark feature, with lat/long coordinates of their centers. You now have your lat/long point mapped to the nearest town/city, ZIP code, county, and state. Now, you can compare that against this list of U.S. Area Codes, to find area codes matching any or all of the identifying information from the USGS. This is all free, and will eventually get you what you need, but you'll probably have to do some work to "massage" the two sets of data into something you can efficiently cross-reference, and/or you'll need to implement a good "search engine" that will accurately find nearest-neighbor named points, and then find area codes for locations matching the names.
One more thing to look at is NANPA, which administers area code assignment to begin with. I'm sure they have a more comprehensive downloadable DB, but the only free public access I could find was this search page, which will find area codes for any city with >20k people. You could turn your lat/long data into a city and state, and then hit this search page: NANPA City Query
Here is an option:
http://geocoder.ca/39.739,-104.985?geoit=xml
<TimeZone>America/Denver</TimeZone>
<AreaCode>720,303</AreaCode

Resources