Re: Is there timezone data for any Indian cities such as Mumbai, Dehli, c.?
On Sun, Aug 19, 2012 at 12:26 AM, Jim Monty jim.mo...@yahoo.com wrote: Ted Byers wrote: I am presently looking at a few perl packages that should facilitate developing such a package (which I will do in due course if no-one identifies one that already exists - I haven't found one). Existing Geo and DateTime Perl modules will do what you said you needed done: look up time zones by city names and then use those time zones in date and time computations. There's no need to write a new module. That depends on how many places in your application, and how many applications you develop, you need this kind of functionality. Granted, the module may be relatively simple, but it would be useful to provide a single function call, for a client application, and have that function look at each option in turn. The packages I am looking at are: Geo::GeoNames Geo::GeoNames::File Geo::Query::LatLong Geo::Location::TimeZone I figure the first two provide for two different ways to use the geonames data. The first uses the geoNames web services (and requires you to sign up for an account - I do not know how long that will continue to be available without cost), and the second provides a way to use the same data from one of their data files that you have downloaded to your own system. I see the second two being a fallback solution if the city in question is not in the geonames database. Geo::Query::LatLong lets you get the latitude and longitude of a city and Geo::Location::TimeZone gives you the timezone for a given position sepcified by latitude and longitude. This strikes me as more sensible, and almost certainly faster, than trying to find the city in the oslen db that is closest to the city for which you want the timezone. The overall logic would be to first see if the city for which you want a timezone is in the Olson DB. If not, check geonames, and if that fails, use the latitude and longitude of the city to get a timezone. The Olson tz database (now, properly, the IANA Time Zone Database) is a database of time zones, not a database of cities. The uniform convention designed by Paul Eggert to name time zones in the database typically includes the name of a representative city within the region defined by the time zone. So which city within the region is used in the name of the time zone? The Wikipedia article titled tz database explains: Usually the most populous city in a region is chosen to represent the entire time zone, although other cities may be selected if they are more widely known or result in a less ambiguous name. ... The location selected is representative for the entire area. http://en.wikipedia.org/wiki/Tz_database#Location I am aware of this, and since the convention for naming the timezones involves the largest city, or small collection of cities, it is something that can be examined to see if the city for which you need a timezone is among these. If it isn't, then it is necessary to look at a db that relates city names to timezones. And since such a database is unlikely to include every municipality on the planet, then it is rational to look at use of a latitude and longitude base option. Yitzchak Scott-Thoennes explained this in a reply to your datetime mailing list inquiry about this same topic in August 2009. He wrote: Within each zone, the most recognizable city is used as the name. In some cases, this isn't the largest. See the comments in the region files for rationales. http://www.nntp.perl.org/group/perl.datetime/2009/08/msg7333.html This I had forgotten. I am also looking at loading the GeoNames data into my databases (Postgresql and MySQL), and accessing that directly instead of accessing it from a text file: this would be to determine which is faster. Consider SQLite. There's an existing module named Geo::GeoNames::DB::SQLite. I noticed, but hadn't examined it closely as I haven't used SQLite, and I am normally using either Postgresql or MySQL. One of the tasks I suppose I will have to do is check to see how many of the time zones in these other sources are incompatible with those in the Olson DB, and then find a mapping of them to the Olson timezones. All you need to determine which time zone a city is in is a database of of time zones by location. The GeoNames geographical database is just such a database. It uses the Olson tz database time zones and time zone names. There are no incompatible time zones in the GeoNames database. One of thee things I was looking for ws just such a database, and is why I was looking at geonames in particular. I didn't know, though, that they used the Olson tz database timezones. That is good to know. Thanks. But there remains the question of possibly incompatible timezone names as the author of the location packeg, that gives timezone as a function of latitude and longitude wrote in his documentation
Is there timezone data for any Indian cities such as Mumbai, Dehli, c.?
I looked and couldn't find any names of Indian cities that I recognized: Dehli, New Dehli, Mumbai, Kolkata Bangalore, Madras, Chandigarh, Amritsar, c., c., c. None of the timezones I found beginning with Indian/ are actually in India. I have built an infrastructure for a web application that makes extensive use of Datetime, and especially the Timezone module, so I now I have a problem in that my colleague pointed out to me he couldn't find any Indian timezone data. But we now have clients in India and we have to support them (and that means that my system for handling timezones is broken unless I find a solution to properly support Indian timezones - i don't know - is there more than one Indian timezone). How do I do that without breaking, or having to spend a lot of time finding a replacement for, my use of Datetime::Timezone? So, are Indian timezones supported, using a name I am not aware of, or is there a way to add support for Indian timezones without breaking anything? Thanks Ted
Re: Is there timezone data for any Indian cities such as Mumbai, Dehli, c.?
Thanks Jim, On Fri, Aug 17, 2012 at 12:24 PM, Jim Monty jim.mo...@yahoo.com wrote: Ted wrote: I looked and couldn't find any names of Indian cities that I recognized: Dehli, New Dehli, Mumbai, Kolkata Bangalore, Madras, Chandigarh, Amritsar, c., c., c. None of the timezones I found beginning with Indian/ are actually in India. So, are Indian timezones supported, using a name I am not aware of, or is there a way to add support for Indian timezones without breaking anything? Yes, of course India is represented in the tz database. It's Asia/Kolkata. See http://en.wikipedia.org/wiki/Asia/Kolkata. And here I was looking for Indian/Kolhata For a convenient list of all the time zones in the tz database, see http://en.wikipedia.org/wiki/List_of_tz_database_time_zones. Given that it seems the entries are generaly 'continent/city',is there something in Datetime that will take any city or state and lookup the entry for the closest city? Or is that something I'll have to write, based on lat/lon data for cities (I am pretty sure I saw a database with lat/lon data for cities somewhere, but ... if it already exists, I don't have to write it)? For everything you ever wanted to know about time and time zones in India, start with http://en.wikipedia.org/wiki/Time_in_India. This article states The IANA time zone database contains only one zone, namely Asia/Kolkata. Read all about the tz database itself in the Wikipedia article http://en.wikipedia.org/wiki/Tz_database. The Perl DateTime module DateTime::TimeZone uses the tz database. Jim Monty Thanks again. Ted.
Re: Is there timezone data for any Indian cities such as Mumbai, Dehli, c.?
On Fri, Aug 17, 2012 at 11:10 PM, Jim Monty jim.mo...@yahoo.com wrote: Thanks again Jim, Ted wrote: Jim wrote: For a convenient list of all the time zones in the tz database, see http://en.wikipedia.org/wiki/List_of_tz_database_time_zones. Given that it seems the entries are generaly 'continent/city', is there something in DateTime that will take any city or state and lookup the entry for the closest city? Or is that something I'll have to write, based on lat/lon data for cities (I am pretty sure I saw a database with lat/lon data for cities somewhere, but ... if it already exists, I don't have to write it)? There aren't any geocoding modules in the Perl DateTime suite (why would there be?), but there *are* plenty of geocoding Perl CPAN modules. Check out the Geo::Coder::* modules, for example. The most obvious reason is that there are a great many more cities in this world than are named in the basic timezone. Such a service is essential if you want to support determination of the proper timezone from, e.g., a mailing address. Given that is seems so obvious to me, it is a wonder that someone hasn't alreay written a package that bridges the gap between geo-coding and the timezone database; but maybe one wouldn't be too hard built on something like the geonames database. If you want to roll your own simple time zone aliases, check out DateTime::TimeZone::Alias: http://search.cpan.org/dist/DateTime-TimeZone-Alias/ The simplest DIY solution is a lookup table using a hash. If you want to do something more elaborate, there are oodles of geocoding resources for programmers on the web: http://en.wikipedia.org/wiki/Geocoding http://askgeo.com/ http://askgeo.com/database/TimeZone http://www.geonames.org/export/web-services.html#timezone http://stackoverflow.com/questions/262264/ http://stackoverflow.com/questions/237023/ http://stackoverflow.com/questions/55901/ http://stackoverflow.com/questions/41504/ Jim Monty I have begun to study the geonames database, but I hadn't happened up their web services. Thanks again Ted
Re: Timezone lookup?
On Wed, Aug 5, 2009 at 10:15 PM, Yitzchak Scott-Thoennessthoe...@efn.org wrote: On Wed, August 5, 2009 12:52 pm, Ted Byers wrote: Is there, in the various timezone packages, support somewhere for finding out what the timezone is for a given city/state? I have, in my database, extensive data with the usual contact information from users from around the world. If at all possible, I would like to query the data managed by one of the timezone packages to determine the local users' timezones from their mailing address. Is this possible? Using what? For countries with a single timezone, you can look it up by iso3166 two character code in %DateTime::TimeZone::Catalog::ZONES_BY_COUNTRY. For other countries, I don't know of such support. You can read the comments in zone.tab or the longer comments in the region files in the tzdata package at ftp://elsie.nci.nih.gov/pub/. Thanks Yitzchak So the short answer is that there is no solution at present. Although we get traffic from all over the world, the bulk of it is from the US and Canada, each of which has several time zones. When I look at the documentation for the timezone catalog, I see for north american data for a small number of cities. Unfortunately that doesn't help for the vast majority of mailing addresses in north america. I naively hoped that someone would have assembled a database mapping state/province codes within countries to their timezones. Isn't it odd that, in the Asia data, there are values for Gaza and Jerusalem, which are only a short distance apart (in terms of how far a crow would have to fly to travel between them, not politically), or more odd, Kuala Lumpur and Singapore (which are separated only by a narrow channel), and yet I don't see any data for the major Indian cities like Mumbai, Calcutta or Delhi. If there are Indian cities represented there, I don't know their names. And THAT strikes me as odd, given that India, by itself, has about a quarter of the world's population and it has some of the world's largest cities. And yet, in the american data, there are values for Glace Bay, Goose Bay, Thunder Bay, Whitehorse. It seems strange that what are tiny little villages are represented while such huge cities are not. Oh well, that's just another thing in this world that doesn't make sense. Thanks anyway, Ted
Re: Timezone lookup?
On Thu, Aug 6, 2009 at 1:10 PM, Karl Youngka...@kipshouse.org wrote: Ted Byers(r.ted.by...@gmail.com)@2009.08.06 10:42:45 -0400: On Wed, Aug 5, 2009 at 10:15 PM, Yitzchak Scott-Thoennessthoe...@efn.org wrote: On Wed, August 5, 2009 12:52 pm, Ted Byers wrote: Is there, in the various timezone packages, support somewhere for finding out what the timezone is for a given city/state? I have, in my database, extensive data with the usual contact information from users from around the world. If at all possible, I would like to query the data managed by one of the timezone packages to determine the local users' timezones from their mailing address. Is this possible? Using what? For countries with a single timezone, you can look it up by iso3166 two character code in %DateTime::TimeZone::Catalog::ZONES_BY_COUNTRY. For other countries, I don't know of such support. You can read the comments in zone.tab or the longer comments in the region files in the tzdata package at ftp://elsie.nci.nih.gov/pub/. Thanks Yitzchak So the short answer is that there is no solution at present. Although we get traffic from all over the world, the bulk of it is from the US and Canada, each of which has several time zones. When I look at the documentation for the timezone catalog, I see for north american data for a small number of cities. Unfortunately that doesn't help for the vast majority of mailing addresses in north america. I naively hoped that someone would have assembled a database mapping state/province codes within countries to their timezones. Thanks Karl, Should be easy enough to do: 50 states in US, and all but a few have a single timezone. Canada has fewer provinces, but I suspect most of them span timezones. Actually, IIRC there are about 5 time zones in Canada, and there are ten provinces and three territories. Alas, I am a rather poor, ignorant Canadian as I can't recall which provinces use which time zones. :-( Or maybe I am just getting senile. :-( These folks: http://www.zip-codes.com/zip-code-database.asp wil sell you a US zipcode database with timezones for $US40. I just learned one of my colleagues found one suitable for the US. Isn't it odd that, in the Asia data, there are values for Gaza and Jerusalem, which are only a short distance apart (in terms of how far a crow would have to fly to travel between them, not politically), or more odd, Kuala Lumpur and Singapore (which are separated only by a narrow channel), and yet I don't see any data for the major Indian cities like Mumbai, Calcutta or Delhi. If there are Indian cities represented there, I don't know their names. And THAT strikes me as odd, given that India, by itself, has about a quarter of the world's population and it has some of the world's largest cities. And yet, in the american data, there are values for Glace Bay, Goose Bay, Thunder Bay, Whitehorse. It seems strange that what are tiny little villages are represented while such huge cities are not. I don't know about the Asian data, but the *Bay and Whitehorse entries are in Canada, and are likely the biggest population centers in their respective timezones. Canada is really big, eh? {-; Canada is now the largest country on the planet (second largest prior to the fracturing of the USSR) in terms of land mass, but it has a population smaller than many of the larger cities in the developing world. And most of Canada's population are within easy commute distance of Toronto, Montreal and Vancouver. It would be a fun exercise to figure out how many of the other provinces would have to be added together to make a population that is of the same order of magnitude as some of the medium sized cities in southern Ontario. ;-) The main geographic reason the US is so large is that there are so many states in it; most of which could be lost in one or more of the great lakes adjacent to Ontario. And you're probably right about *bay and Whitehorse being the largest population centres in their regions. But Thunder Bay is in Ontario, and is quite small relative to the main cities in southern Ontario (e.g. Toronto) And so, since timezones are not likely defined by latitude, it is certain there are many other cities in their timezones that are much larger (even thought those other cities are hundreds if not thousands of miles away). Cheers, Ted Oh well, that's just another thing in this world that doesn't make sense. Thanks anyway, Ted
Re: Timezone lookup?
On Thu, Aug 6, 2009 at 10:27 PM, Jim Brunetteca...@brownhare.com wrote: Is there a lat/lon database that contains the timezone boundaries? With a lat/long TZ DB, users could input their city or zip (or heck, if they know it, their lat/lon), then the app would associate the user's lat/lon with the TZ lat/lon and output the TZ (if the user's lat/lon was not found, the app would just fall back to the continent/city names). To take it one step further, mobile apps with GPS have real-time lat/lon, so getting the TZ should be easy... How useful such an mobile app would be is another question. Jim Hey Jim, I have seen a suite of mobile apps using GPS data. In fact, one of the earliest commercial apps I developed involved using GPS to produce mapping info for farms (do a search on precision agriculture to get a sense of the kind of app that was - but it is certain it is no longer on the market as it was designed to crawl on DOS ;-) Find a task where time of day is as important as location, and you have the potential for such a mobile app. Theoretically, you're right, as long as there is a lat/lon DB containing TZ boundaries. But in practical terms, it is another question. Determining whether or not a given point is within the bounds of a given polygon in 2D is not trivial. It can be done, and there are well established algorithms to support it, but it carries a cost; and you can multiply that cost by the average number of polygons you have to check before you get the right one. Is there enough hardware supporting the app for the peak number of users? And the list of complications and constraints goes on. Cheers, Ted
Re: Timezone lookup?
On Thu, Aug 6, 2009 at 10:39 PM, J. Shirleyjshir...@gmail.com wrote: On Thu, Aug 6, 2009 at 7:27 PM, Jim Brunette ca...@brownhare.com wrote: Is there a lat/lon database that contains the timezone boundaries? With a lat/long TZ DB, users could input their city or zip (or heck, if they know it, their lat/lon), then the app would associate the user's lat/lon with the TZ lat/lon and output the TZ (if the user's lat/lon was not found, the app would just fall back to the continent/city names). To take it one step further, mobile apps with GPS have real-time lat/lon, so getting the TZ should be easy... How useful such an mobile app would be is another question. Jim geonames.org provides this, via a simple HTTP interface. Here's a blog post describing usage: http://vancouverwebconsultants.com/getting-time-zone-from-latitude-longitude/(though in PHP) To fetch, it's very simple: http://ws.geonames.org/timezone?lat=$latlng=$lng -J Well live and learn. Use someone else's hardware and software to do the heavy lifting. ... ;-) I'll have to check it out. It is trivial to write Perl that is equivalent to a given PHP code snippet. ;-) Thanks Ted
Timezone lookup?
Is there, in the various timezone packages, support somewhere for finding out what the timezone is for a given city/state? I have, in my database, extensive data with the usual contact information from users from around the world. If at all possible, I would like to query the data managed by one of the timezone packages to determine the local users' timezones from their mailing address. Is this possible? Using what? This data also has date and time stamps in UTC, and converting these to whatever timezone is desired is easy to do using any of several datetime packages I have tried. But the problem remains to figure out what time zone to use when ALL you have for a given person is his mailing address. Can that problem be solved? Thanks Ted
Re: RFC:: DateTime::Span::Common
On Tue, Apr 7, 2009 at 4:02 PM, Terrence Brannon scheme...@gmail.com wrote: On Tue, Mar 31, 2009 at 2:17 PM, Zefram zef...@fysh.org wrote: Terrence Brannon wrote: Intuitively, it would seem that specifying the 'before' of a datetime span using the end option of the -from_datetimes() constructor would yield a range that is 1 second (1 nanosecond?) earlier than the actual date supplied. I would not find that intuitive. Your 1 second or 1 nanosecond would be a completely arbitrary mutation of the supplied data. Neither would I. Yes, I would determine that aribtrary 1 second or nanosecond based on the data in my database tables. a MySQL BETWEEN clause includes its endpoints. That is correct. If I want all data for a certain date, my BETWEEN clause must be from 00:00::00 to 23:59:59 assuming a datetime column. That is not correct, UNLESS you ALSO want to support arbitrary intervals that include part days. Otherwise, if you know the date for which you want your data, you can cast the datetime to a date and test for equality against the date you require. I use that trick all the time, even when I need to take time zones into account (provided MySQL knows about the time zone in question). And it works fine for arbitrary periods as long as the temporal granularity is a day. Using the start and end dates supplied by Datetime::Span would lead to overlapping SQL query results on successive days, hence the following module: use DateTime::Span::Common; # ideal for DATETIME columns my $x = DateTime::Span::Common-new(shave = [seconds = 1]); # not sure what this would be practical for my $y = DateTime::Span::Common-new(shave = [nanoseconds = 1]); my @dto = $x-today; �...@dto = $x-yesterday; �...@dto = $x-this_week; �...@dto = $x-last_week; �...@dto = $x-this_month; �...@dto = $x-last_month; �...@dto = $x-year_to_date; �...@dto = $x-last_year; my $sth = $dbh-prepare('SELECT * FROM table WHERE order_date BETWEEN ? AND ?'); $sth-execute(@dto); Hm Interesting. I will have to look into DateTime::Span, especially how it works with timezones. That is a neat construct. When I have had to use perl to compute dates and times, I have used either Date::manip or datetime, for calculations involving time zones and taking into account that our different offices are in different time zones, but I hadn't looked at DateTime::Span yet. Surely, if you ask it for time stamps that include all valid times for a given day (or a set of such intervals for a series of days), it will give you times from 00:00:00 to 23:59:59 (as a closed interval). The only way I can see it giving you overlapping intervals is if it gives you a half open interval (00:00:00 on one day and 00:00:00 on the next day): and that doesn't strike me as intuitive (unless it is documented as behaving like that: in which case I would derive a new class from it to give me a closed interval I can use). Just a thought. Ted