Date/I18Nv2 - how to select user timezone
| From: | Andreas Korthaus | Date: | Wed, 02 Mar 2005 23:51:50 +0000 |
| Subject: | Date/I18Nv2 - how to select user timezone | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-36497@lists.php.net to get a copy of this message | ||
Hello!
Is there a nice way implemented in PEAR::Date to let the user select his own timezone? You can set the timezone, e.g. "America/New_York", but if this timezone is different from servers timezone - where do you get the string "America/New_York" from? If you have users who want to use their own, local timezones in the web application, they must select the timezone themself. But this is not easy, because you have several problems:
1. daylight saving start+end date is not the same everywhere: http://www.worldtimezone.com/daylight.html
2. difference between Northern Hemisphere and Southern Hemisphere
3. many countries do not use daylight-savings at all
So you cannot use only PST, CET..., because different regions/countries in one timezone can have different times because of daylight savings. PEAR::Date takes care of this (using putenv('TZ...') and localeconv()) so the following solves these issues:
<?php
$date= new Date();
$ny_tz= new Date_Timezone("America/New_York");
$date->converttz($ny_tz);
?>
But to use this I need the users exact timezone/location ("America/New_York") as used in /usr/share/zoneinfo on unix-systems. If I count all possible regions in /usr/share/zoneinfo, I get about 300 values. So the user could select his timezone out of such a large drop-down with values as
[...]
America/Merida
America/Mexico_City
America/Miquelon
America/Monterrey
America/Montevideo
America/Montreal
America/Montserrat
America/Nassau
America/New_York
[...]
I do not think that is very nice for a user. A better way to select this is how Windows lets the user select a timezone. Windows groups regions that have the same timezone and same DST dates. So you have something like
[...]
(GMT-06:00) Chicago, Dallas, Kansas City, Winnipeg
(GMT-06:00) Saskatchewan
(GMT-05:00) New York, Miami, Atlanta, Detroit, Toronto
(GMT-05:00) Bogotá, Lima, Quito
[...]
(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones)
IMO this is a nice list for a user to select his own timezone. So I thought about building an array, something like that:
$tz_map = array(
[...]
'America/Chicago' => '(GMT-06:00) Chicago, Dallas, Kansas City, Winnipeg',
'America/Scoresbysund' => '(GMT-06:00) Saskatchewan',
'America/New_York' => '(GMT-05:00) New York, Miami, Atlanta, Detroit, Toronto',
'America/Bogota' => '(GMT-05:00) Bogotá, Lima, Quito',
[...]
);
Or perhaps split it to extract offset to GMT (or use the value from PEAR::Date?). With such an array I could build a drop-down which is very easy to use. I think this mapping should work correct. The only problem is the translation. On my machine I have german strings as "Kapverdische Inseln" (Cape Verde Islands) or "Grönland" (Greenland). So it would be nice to get a translated version (in many languages, as I18Nv2 countries...) of that table/array.
I know that this is the simplest way to use this data, I'm sure there are more beautiful ways to integrate this.
What do you think about that? Do you see a chance to integrate something like that into Date or I18Nv2 or something else?
Or does PEAR provide a better way I did not found, yet?
Or do you think it is too special?
kind regards
Andreas