duanpanhuo0618 2015-04-28 17:31
浏览 61
已采纳

PHP时区列表不一致

so I'm using drupal 6's date_timezone_names to generate a list of timezones:

/**
 * A translated array of timezone names.
 * Cache the untranslated array, make the translated array a static variable.
 *
 * @param $required
 *   If not required, returned array will include a blank value.
 * @return
 *   an array of timezone names
 */
function date_timezone_names($required = FALSE, $refresh = FALSE) {
  static $zonenames;
  if (empty($zonenames) || $refresh) {
    $cached = cache_get('date_timezone_identifiers_list');
    $zonenames = !empty($cached) ? $cached->data : array();
    if ($refresh || empty($cached) || empty($zonenames)) {
      $data = timezone_identifiers_list(DateTimeZone::ALL_WITH_BC);
      // Use include instead of include once in case the function gets
      // refreshed via devel or other API and is called more than once.
      if (module_exists('date_php4')) {
        include('./'. drupal_get_path('module', 'date_php4') .'/date_php4_missing_data.inc');
      }
      foreach ($data as $delta => $zone) {
        // Because many time zones exist in PHP only for backward
        // compatibility reasons and should not be used, the list is
        // filtered by a regular expression.
        if (preg_match('!^((Africa|America|Antarctica|Arctic|Asia|Atlantic|Australia|Europe|Indian|Pacific)/|UTC$)!', $zone)) {
          // https://github.com/Br3nda/drupal-module-date/blob/master/date_api.module
          $zonenames[$zone] = $zone;
        }
      }
      // If using PHP4, filter the list down to only the timezones
      // the PHP4 wrapper has data for.
      if (module_exists('date_php4')) {
        foreach ($missing_timezone_data as $zone) {
          unset($zonenames[$zone]);
        }
      }

      // If using Event, further filter the list down to only
      // zones that exist in the event module.
      if (module_exists('event') && db_table_exists('event_timezones')) {
        $result = db_query("SELECT name FROM {event_timezones} ORDER BY name");
        $names = array();
        while ($row = db_fetch_array($result)) {
          $names[] = str_replace(' ', '_', $row['name']);
        }
        foreach ($zonenames as $name => $zone) {
          if (!in_array($name, $names)) {
            unset($zonenames[$name]);
          }
        }
      }
      if (!empty($zonenames)) {
        cache_set('date_timezone_identifiers_list', $zonenames);
      }
    }
    foreach ($zonenames as $zone) {
      $zonenames[$zone] = t($zone);
    }
  }
  $none = array('' => '');
  return !$required ? $none + $zonenames : $zonenames;
}

notice that eventually it calls timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)

but then this sometimes returns inconsistent list...sometimes timezones such as Asia/Chita (GMT+8) is present in the list...othertimes, that timezone doesn't exist in the list....also note that Asia/Chita is NOT in date_php4_missing_data.inc

any idea why this would happen? in what scenario would $data = timezone_identifiers_list(DateTimeZone::ALL_WITH_BC); return inconsistent list of timezones?

Another timezone that sometimes appear sometimes doesnt: Asia/Srednekolymsk ... notice that this also is NOT in date_php4_missing_data.inc

  • 写回答

1条回答 默认 最新

  • dsepcxw181184853 2015-04-29 07:22
    关注

    Both Asia/Chita and Asia/Srednekolymsk were added to the tzdb in 2014f (announcement here). This update corresponds to PHP's timezonedb version 2014.6.

    You can see the current version of timezonedb installed by timezone_version_get(), as documented here.

    It is entirely possible to have PHP installations with different versions of the timezonedb, whether due to running an older version of PHP itself, or having manually updated the timezonedb PECL package. If you care about up-to-date time zones, then you should subscribe to the IANA tz announcements mailing list, and apply corresponding updates to PHP's timezonedb as necessary.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值