Changeset 5879c09 in github


Ignore:
Timestamp:
Jan 4, 2012 7:47:50 AM (18 months ago)
Author:
thomascube <thomas@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.8
Children:
e2c9ab4
Parents:
7645a0a
Message:

Use proper timezones from PHP's internal timezonedb (#1485592)

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • CHANGELOG

    r08ffd939 r5879c09  
    22=========================== 
    33 
     4- Use proper timezones from PHP's internal timezonedb (#1485592) 
    45- Add separate pagesize setting for mail messages and contacts (#1488269) 
    56- Fix handling of INBOX's subfolders in special folders config (#1488279) 
  • config/main.inc.php.dist

    r08ffd939 r5879c09  
    662662 
    663663// use this timezone to display date/time 
     664// valid timezone identifers are listed here: php.net/manual/en/timezones.php 
     665// 'auto' will use the browser's timezone settings 
    664666$rcmail_config['timezone'] = 'auto'; 
    665  
    666 // is daylight saving On? Default: (bool)date('I'); 
    667 $rcmail_config['dst_active'] = null; 
    668667 
    669668// prefer displaying HTML messages 
  • program/include/main.inc

    r672dc41 r5879c09  
    10631063    return ''; 
    10641064 
    1065   if ($convert) { 
    1066     // get user's timezone offset 
    1067     $tz = $RCMAIL->config->get_timezone(); 
    1068  
    1069     // convert time to user's timezone 
    1070     $timestamp = $ts - date('Z', $ts) + ($tz * 3600); 
    1071  
    1072     // get current timestamp in user's timezone 
    1073     $now = time();  // local time 
    1074     $now -= (int)date('Z'); // make GMT time 
    1075     $now += ($tz * 3600); // user's time 
    1076   } 
    1077   else { 
    1078     $now       = time(); 
    1079     $timestamp = $ts; 
    1080   } 
     1065  $date = new DateTime; 
     1066  $date->setTimestamp($ts); 
     1067 
     1068  // convert to the right timezone 
     1069  $stz = date_default_timezone_get(); 
     1070  $tz = new DateTimeZone($convert ? $RCMAIL->config->get('timezone') : 'GMT'); 
     1071  date_default_timezone_set($tz->getName()); 
     1072  $date->setTimezone($tz); 
     1073 
     1074  $timestamp = $date->getTimestamp(); 
    10811075 
    10821076  // define date format depending on current time 
     
    10991093  if (preg_match('/%[a-z]+/i', $format)) { 
    11001094    $format = strftime($format, $timestamp); 
     1095    date_default_timezone_set($stz); 
    11011096    return $today ? (rcube_label('today') . ' ' . $format) : $format; 
    11021097  } 
     
    11141109    // weekday (short) 
    11151110    else if ($format[$i]=='D') 
    1116       $out .= rcube_label(strtolower(date('D', $timestamp))); 
     1111      $out .= rcube_label(strtolower($date->format('D'))); 
    11171112    // weekday long 
    11181113    else if ($format[$i]=='l') 
    1119       $out .= rcube_label(strtolower(date('l', $timestamp))); 
     1114      $out .= rcube_label(strtolower($date->format('l'))); 
    11201115    // month name (short) 
    11211116    else if ($format[$i]=='M') 
    1122       $out .= rcube_label(strtolower(date('M', $timestamp))); 
     1117      $out .= rcube_label(strtolower($date->format('M'))); 
    11231118    // month name (long) 
    11241119    else if ($format[$i]=='F') 
    1125       $out .= rcube_label('long'.strtolower(date('M', $timestamp))); 
     1120      $out .= rcube_label('long'.strtolower($date->format('M'))); 
    11261121    else if ($format[$i]=='x') 
    11271122      $out .= strftime('%x %X', $timestamp); 
    11281123    else 
    1129       $out .= date($format[$i], $timestamp); 
     1124      $out .= $date->format($format[$i]); 
    11301125  } 
    11311126 
     
    11411136  } 
    11421137 
     1138  date_default_timezone_set($stz); 
    11431139  return $out; 
    11441140} 
     
    18791875function rcmail_user_date() 
    18801876{ 
    1881   global $RCMAIL, $CONFIG; 
     1877  global $RCMAIL; 
    18821878 
    18831879  // get user's timezone 
    1884   $tz = $RCMAIL->config->get_timezone(); 
    1885  
    1886   $date = time() + $tz * 60 * 60; 
    1887   $date = gmdate('r', $date); 
    1888   $tz   = sprintf('%+05d', intval($tz) * 100 + ($tz - intval($tz)) * 60); 
    1889   $date = preg_replace('/[+-][0-9]{4}$/', $tz, $date); 
    1890  
    1891   return $date; 
     1880  $tz = new DateTimeZone($RCMAIL->config->get('timezone')); 
     1881 
     1882  $date = new DateTime('now', $tz); 
     1883  return $date->format('r'); 
    18921884} 
    18931885 
  • program/include/rcube_config.php

    r0829b76 r5879c09  
    9494        // set timezone auto settings values 
    9595        if ($this->prop['timezone'] == 'auto') { 
    96           $this->prop['dst_active'] = intval(date('I')); 
    97           $this->prop['_timezone_value'] = date('Z') / 3600 - $this->prop['dst_active']; 
    98         } 
    99         else if ($this->prop['dst_active'] === null) { 
    100           $this->prop['dst_active'] = intval(date('I')); 
    101         } 
     96          $this->prop['_timezone_value'] = $this->client_timezone(); 
     97        } 
     98        else if (is_numeric($this->prop['timezone'])) { 
     99          $this->prop['timezone'] = timezone_name_from_abbr("", $this->prop['timezone'] * 3600, 0); 
     100        } 
     101 
     102        // remove deprecated properties 
     103        unset($this->prop['dst_active']); 
    102104 
    103105        // export config data 
     
    223225        // override timezone settings with client values 
    224226        if ($this->prop['timezone'] == 'auto') { 
    225             $this->prop['_timezone_value'] = isset($_SESSION['timezone']) ? $_SESSION['timezone'] : $this->prop['_timezone_value']; 
    226             $this->prop['dst_active'] = $this->userprefs['dst_active'] = isset($_SESSION['dst_active']) ? $_SESSION['dst_active'] : $this->prop['dst_active']; 
     227            $this->prop['_timezone_value'] = isset($_SESSION['timezone']) ? $this->client_timezone() : $this->prop['_timezone_value']; 
    227228        } 
    228229        else if (isset($this->prop['_timezone_value'])) 
     
    245246     * 
    246247     * @return float  Timezone offset (in hours) 
     248     * @deprecated 
    247249     */ 
    248250    public function get_timezone() 
    249251    { 
    250       return floatval($this->get('timezone')) + intval($this->get('dst_active')); 
     252      if ($this->get('timezone')) { 
     253        $tz = new DateTimeZone($this->get('timezone')); 
     254        return $tz->getOffset(new DateTime('now')) / 3600; 
     255      } 
     256 
     257      return 0; 
    251258    } 
    252259 
     
    350357    } 
    351358 
     359 
     360    /** 
     361     * Internal getter for client's (browser) timezone identifier 
     362     */ 
     363    private function client_timezone() 
     364    { 
     365        return isset($_SESSION['timezone']) ? timezone_name_from_abbr("", $_SESSION['timezone'] * 3600, 0) : date_default_timezone_get(); 
     366    } 
     367 
    352368} 
  • program/steps/settings/func.inc

    ra61ccea r5879c09  
    178178    if (!isset($no_override['timezone'])) { 
    179179      $field_id = 'rcmfd_timezone'; 
    180       $select_timezone = new html_select(array('name' => '_timezone', 'id' => $field_id, 
    181         'onchange' => "$('#rcmfd_dst').attr('disabled', this.selectedIndex==0)")); 
     180      $select_timezone = new html_select(array('name' => '_timezone', 'id' => $field_id)); 
    182181      $select_timezone->add(rcube_label('autodetect'), 'auto'); 
    183       $select_timezone->add('(GMT -11:00) Midway Island, Samoa', '-11'); 
    184       $select_timezone->add('(GMT -10:00) Hawaii', '-10'); 
    185       $select_timezone->add('(GMT -9:30) Marquesas Islands', '-9.5'); 
    186       $select_timezone->add('(GMT -9:00) Alaska', '-9'); 
    187       $select_timezone->add('(GMT -8:00) Pacific Time (US/Canada)', '-8'); 
    188       $select_timezone->add('(GMT -7:00) Mountain Time (US/Canada)', '-7'); 
    189       $select_timezone->add('(GMT -6:00) Central Time (US/Canada), Mexico City', '-6'); 
    190       $select_timezone->add('(GMT -5:00) Eastern Time (US/Canada), Bogota, Lima', '-5'); 
    191       $select_timezone->add('(GMT -4:30) Caracas', '-4.5'); 
    192       $select_timezone->add('(GMT -4:00) Atlantic Time (Canada), La Paz', '-4'); 
    193       $select_timezone->add('(GMT -3:30) Nfld Time (Canada), Nfld, S. Labador', '-3.5'); 
    194       $select_timezone->add('(GMT -3:00) Brazil, Buenos Aires, Georgetown', '-3'); 
    195       $select_timezone->add('(GMT -2:00) Mid-Atlantic', '-2'); 
    196       $select_timezone->add('(GMT -1:00) Azores, Cape Verde Islands', '-1'); 
    197       $select_timezone->add('(GMT) Western Europe, London, Lisbon, Casablanca', '0'); 
    198       $select_timezone->add('(GMT +1:00) Central European Time', '1'); 
    199       $select_timezone->add('(GMT +2:00) EET: Tallinn, Helsinki, Kaliningrad, South Africa', '2'); 
    200       $select_timezone->add('(GMT +3:00) Baghdad, Kuwait, Riyadh, Moscow, Nairobi', '3'); 
    201       $select_timezone->add('(GMT +3:30) Tehran', '3.5'); 
    202       $select_timezone->add('(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi', '4'); 
    203       $select_timezone->add('(GMT +4:30) Kabul', '4.5'); 
    204       $select_timezone->add('(GMT +5:00) Ekaterinburg, Islamabad, Karachi', '5'); 
    205       $select_timezone->add('(GMT +5:30) Chennai, Kolkata, Mumbai, New Delhi', '5.5'); 
    206       $select_timezone->add('(GMT +5:45) Kathmandu', '5.75'); 
    207       $select_timezone->add('(GMT +6:00) Almaty, Dhaka, Colombo', '6'); 
    208       $select_timezone->add('(GMT +6:30) Cocos Islands, Myanmar', '6.5'); 
    209       $select_timezone->add('(GMT +7:00) Bangkok, Hanoi, Jakarta', '7'); 
    210       $select_timezone->add('(GMT +8:00) Beijing, Perth, Singapore, Taipei', '8'); 
    211       $select_timezone->add('(GMT +8:45) Caiguna, Eucla, Border Village', '8.75'); 
    212       $select_timezone->add('(GMT +9:00) Tokyo, Seoul, Yakutsk', '9'); 
    213       $select_timezone->add('(GMT +9:30) Adelaide, Darwin', '9.5'); 
    214       $select_timezone->add('(GMT +10:00) EAST/AEST: Sydney, Guam, Vladivostok', '10'); 
    215       $select_timezone->add('(GMT +10:30) New South Wales', '10.5'); 
    216       $select_timezone->add('(GMT +11:00) Magadan, Solomon Islands', '11'); 
    217       $select_timezone->add('(GMT +11:30) Norfolk Island', '11.5'); 
    218       $select_timezone->add('(GMT +12:00) Auckland, Wellington, Kamchatka', '12'); 
    219       $select_timezone->add('(GMT +12:45) Chatham Islands', '12.75'); 
    220       $select_timezone->add('(GMT +13:00) Tonga, Pheonix Islands', '13'); 
    221       $select_timezone->add('(GMT +14:00) Kiribati', '14'); 
     182 
     183      $now = new DateTime(); 
     184      foreach (DateTimeZone::listIdentifiers() as $i => $tzs) { 
     185        $tz = new DateTimeZone($tzs); 
     186        $date = new DateTime('2012-12-21', $tz); 
     187        $offset = $date->format('Z') + 45000; 
     188        $sortkey = sprintf('%06d.%s', $offset, $tzs); 
     189        $zones[$sortkey] = array($tzs, $date->format('P')); 
     190      } 
     191 
     192      ksort($zones); 
     193      foreach ($zones as $zone) { 
     194        list($tzs, $offset) = $zone; 
     195        $select_timezone->add('(GMT ' . $offset . ') ' . strtr($tzs, '_', ' '), $tzs); 
     196      } 
     197 
     198      if (is_numeric($config['timezone'])) 
     199        timezone_name_from_abbr("", $config['timezone'] * 3600, 0); 
    222200 
    223201      $blocks['main']['options']['timezone'] = array( 
    224202        'title' => html::label($field_id, Q(rcube_label('timezone'))), 
    225203        'content' => $select_timezone->show((string)$config['timezone']), 
    226       ); 
    227     } 
    228  
    229     // daylight savings 
    230     if (!isset($no_override['dst_active'])) { 
    231       $field_id = 'rcmfd_dst'; 
    232       $input_dst = new html_checkbox(array('name' => '_dst_active', 'id' => $field_id, 'value' => 1, 'disabled' => ($config['timezone'] === 'auto'))); 
    233  
    234       $blocks['main']['options']['dstactive'] = array( 
    235         'title' => html::label($field_id, Q(rcube_label('dstactive'))), 
    236         'content' => $input_dst->show($config['dst_active']), 
    237204      ); 
    238205    } 
  • program/steps/settings/save_prefs.inc

    r08ffd939 r5879c09  
    3030    $a_user_prefs = array( 
    3131      'language'     => isset($_POST['_language']) ? get_input_value('_language', RCUBE_INPUT_POST) : $CONFIG['language'], 
    32       'timezone'     => isset($_POST['_timezone']) ? (is_numeric($_POST['_timezone']) ? floatval($_POST['_timezone']) : get_input_value('_timezone', RCUBE_INPUT_POST)) : $CONFIG['timezone'], 
    33       'dst_active'   => isset($_POST['_dst_active']) ? TRUE : FALSE, 
     32      'timezone'     => isset($_POST['_timezone']) ? get_input_value('_timezone', RCUBE_INPUT_POST) : $CONFIG['timezone'], 
    3433      'date_format'  => isset($_POST['_date_format']) ? get_input_value('_date_format', RCUBE_INPUT_POST) : $CONFIG['date_format'], 
    3534      'time_format'  => isset($_POST['_time_format']) ? get_input_value('_time_format', RCUBE_INPUT_POST) : ($CONFIG['time_format'] ? $CONFIG['time_format'] : 'H:i'), 
Note: See TracChangeset for help on using the changeset viewer.