Peter,

according to the W3C headers there are 2 ways:

* Get the date header from the browser. Use it as input for Zend_Date using the W3C constant.
But you should note that this header can be supressed.

* Get the locale of the user and use Zend_Locale::getTranslation/getTranslationList() to get a relation between the full locale and the timezone. Note that the user can supress the locale and that it is also possible that he uses only a language (f.e. en) which would not allow to detect a language (en is supported in about 15 timezones)

* Then use again Zend_Date to get the offset between your timezone and the detected timezone.

Again:
As the user can supress EVERY of the mentioned headers there is no 100% perfect way of automatically detecting a users timezone.

Btw: Just to note and related to your code... Zend_Locale::getTranslationList() returns you a localized list of timezones... a german user would for example like to see "Mitteleuropäische Sommerzeit" instead of "Central European Time".

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message ----- From: "Peter Wansch" <[email protected]>
To: <[email protected]>
Sent: Friday, May 01, 2009 7:08 AM
Subject: Re: [fw-general] Getting the timezone from the browser's offset



Hi Thomas,
I was looking at the API doc for Zend_Date or Zend_Locale to find something
that would return for instance America/Los_Angeles. Any pointer is much
appreciated.
Danke!!
Peter

thomasW wrote:

You can use Zend_Date or Zend_Locale for this purpose.
But it is also not problematic to realize this manually.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message ----- From: "Peter Wansch" <[email protected]>
To: <[email protected]>
Sent: Thursday, April 30, 2009 5:18 PM
Subject: [fw-general] Getting the timezone from the browser's offset



Hi,
In our application, we let users select Timezones. To render a timezone
list
we use the following view helper which works great:

class Ggv_View_Helper_TimezonesList extends Zend_View_Helper_Abstract
{
   public function timezonesList($selectedzone, $label, $name =
'timezone',
$desc = '')
   {
       //$output = '<div class="label"><label for="' . $name .
'">'.$label.':</label></div>';
       $output = '<div class="input"><select name="' . $name . '">';
       $output .= $this->timezonechoice($selectedzone);
       $output .= '</select>';
       $output .= ' '.$desc.' </div>';
       return $output;
   }

   protected function timezonechoice($selectedzone)
   {
       $all = timezone_identifiers_list();

       $i = 0;
       foreach($all as $zone)
       {
           $zone = explode('/', $zone);
           $zones[$i]['continent'] = isset($zone[0]) ? $zone[0] : '';
           $zones[$i]['city'] = isset($zone[1]) ? $zone[1] : '';
           $zones[$i]['subcity'] = isset($zone[2]) ? $zone[2] : '';
           $i++;
       }

       asort($zones);
       $structure = '';
       foreach($zones as $zone)
       {
           extract($zone);
           if($continent == 'Africa' || $continent == 'America' ||
$continent == 'Antarctica' || $continent == 'Arctic' || $continent ==
'Asia'
|| $continent == 'Atlantic' || $continent == 'Australia' || $continent ==
'Europe' || $continent == 'Indian' || $continent == 'Pacific')
           {
               if(!isset($selectcontinent))
               {
$structure .= '<optgroup label="' . $continent . '">';
// continent
               }
               elseif($selectcontinent != $continent)
               {
                   $structure .= '</optgroup><optgroup label="' .
$continent . '">'; // continent
               }

               if(isset($city) != '')
               {
                   if (!empty($subcity) != '')
                   {
                       $city = $city . '/' . $subcity;
                   }
                   $structure .= "<option " . ((($continent . '/' .
$city)
== $selectedzone) ? 'selected="selected "' : '')." value=\"" .
($continent
.
'/' . $city) . "\">" . str_replace('_', ' ', $city) . "</option>"; //
timezone
               }
               else
               {
                   if (!empty($subcity) != '')
                   {
                       $city = $city . '/'. $subcity;
                   }
                   $structure .= "<option " . (($continent ==
$selectedzone) ? 'selected="selected "' : '') . " value=\"" . $continent
.
"\">" . $continent . "</option>"; // timezone
               }

               $selectcontinent = $continent;
           }
       }
       $structure .= '</optgroup>';
       return $structure;
   }
}


In the phtml view script we use the following which also works nicely:

<dt><label for="user_join_communityTimeZone"><?=
$this->translate('Community
Time Zone:') ?></label></dt>


In our controller, we set the user_join_communityTimezZone to:

date_default_timezone_get());

so the default is the system timezone.

Is there an (easy way) without figuring out myself from the offset header
to
detect the most likely user timezone to avoid user error?
--
View this message in context:
http://www.nabble.com/Getting-the-timezone-from-the-browser%27s-offset-tp23269606p23269606.html
Sent from the Zend Framework mailing list archive at Nabble.com.




--
View this message in context: http://www.nabble.com/Getting-the-timezone-from-the-browser%27s-offset-tp23269606p23328538.html Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to