当前位置: 首页>>代码示例>>PHP>>正文


PHP sfCultureInfo::getTimeZones方法代码示例

本文整理汇总了PHP中sfCultureInfo::getTimeZones方法的典型用法代码示例。如果您正苦于以下问题:PHP sfCultureInfo::getTimeZones方法的具体用法?PHP sfCultureInfo::getTimeZones怎么用?PHP sfCultureInfo::getTimeZones使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sfCultureInfo的用法示例。


在下文中一共展示了sfCultureInfo::getTimeZones方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: select_timezone_tag

/**
 * Returns a <select> tag populated with all the timezones in the world.
 *
 * The select_timezone_tag builds off the traditional select_tag function, and is conveniently populated with 
 * all the timezones in the world (sorted alphabetically). Each option in the list has a unique timezone identifier 
 * for its value and the timezone's locale as its display title.  The timezone data is retrieved via the sfCultureInfo
 * class, which stores a wide variety of i18n and i10n settings for various countries and cultures throughout the world.
 * Here's an example of an <option> tag generated by the select_timezone_tag:
 *
 * <b>Options:</b>
 * - display - 
 *     identifer         - Display the PHP timezone identifier (e.g. America/Denver)
 *     timezone          - Display the full timezone name (e.g. Mountain Standard Time)
 *     timezone_abbr     - Display the timezone abbreviation (e.g. MST)
 *     timzone_dst       - Display the full timezone name with daylight savings time (e.g. Mountain Daylight Time)
 *     timezone_dst_abbr - Display the timezone abbreviation with daylight savings time (e.g. MDT)
 *     city              - Display the city/region that relates to the timezone (e.g. Denver)
 * 
 * <samp>
 *  <option value="America/Denver">America/Denver</option>
 * </samp>
 *
 * <b>Examples:</b>
 * <code>
 *  echo select_timezone_tag('timezone', 'America/Denver');
 * </code>
 *
 * @param  string field name 
 * @param  string selected field value (timezone identifier)
 * @param  array  additional HTML compliant <select> tag parameters
 * @return string <select> tag populated with all the timezones in the world.
 * @see select_tag, options_for_select, sfCultureInfo
 */
function select_timezone_tag($name, $selected = null, $options = array())
{
    if (!isset($options['display'])) {
        $options['display'] = 'identifier';
    }
    $c = new sfCultureInfo(sfContext::getInstance()->getUser()->getCulture());
    $timezone_groups = $c->getTimeZones();
    $display_key = 0;
    switch ($options['display']) {
        case "identifier":
            $display_key = 0;
            break;
        case "timezone":
            $display_key = 1;
            break;
        case "timezone_abbr":
            $display_key = 2;
            break;
        case "timezone_dst":
            $display_key = 3;
            break;
        case "timezone_dst_abbr":
            $display_key = 4;
            break;
        case "city":
            $display_key = 5;
            break;
        default:
            $display_key = 0;
            break;
    }
    unset($options['display']);
    $timezones = array();
    foreach ($timezone_groups as $tz_group_key => $tz_group) {
        $array_key = null;
        foreach ($tz_group as $tz_key => $tz) {
            if ($tz_key == 0) {
                $array_key = $tz;
            }
            if ($tz_key == $display_key and !empty($tz)) {
                $timezones[$array_key] = $tz;
            }
        }
    }
    if ($timezone_option = _get_option($options, 'timezones')) {
        $diff = array_diff_key($timezones, array_flip((array) $timezone_option));
        foreach ($diff as $key => $v) {
            unset($timezones[$key]);
        }
    }
    // Remove duplicate values
    $timezones = array_unique($timezones);
    asort($timezones);
    $option_tags = options_for_select($timezones, $selected);
    return select_tag($name, $option_tags, $options);
}
开发者ID:jonphipps,项目名称:Metadata-Registry,代码行数:89,代码来源:DateFormHelper.php

示例2:

$countries_en = $c_en->getCountries();
$countries_fr = $c_fr->getCountries();
$t->is($countries_en['ES'], 'Spain', '->getCountries() returns a list of countries in the language of the localized version');
$t->is($countries_fr['ES'], 'Espagne', '->getCountries() returns a list of countries in the language of the localized version');
$t->is($countries_en, $c_en->Countries, '->getCountries() is equivalent to ->Countries');
// ->getScripts()
$t->diag('->getScripts()');
$scripts_en = $c_en->getScripts();
$scripts_fr = $c_fr->getScripts();
$t->is($scripts_en['Arab'], 'Arabic', '->getScripts() returns a list of scripts in the language of the localized version');
$t->is($scripts_fr['Arab'], 'arabe', '->getScripts() returns a list of scripts in the language of the localized version');
$t->is($scripts_en, $c_en->Scripts, '->getScripts() is equivalent to ->Scripts');
// ->getTimeZones()
$t->diag('->getTimeZones()');
$time_zones_en = $c_en->getTimeZones();
$time_zones_fr = $c_fr->getTimeZones();
$t->is($time_zones_en[1][0], 'America/Los_Angeles', '->getTimeZones() returns a list of time zones in the language of the localized version');
$t->is($time_zones_fr[1][0], 'America/Vancouver', '->getTimeZones() returns a list of time zones in the language of the localized version');
$t->is($time_zones_en, $c_en->TimeZones, '->getTimeZones() is equivalent to ->TimeZones');
// ->validCulture()
$t->diag('->validCulture()');
$t->is($c->validCulture('fr'), true, '->validCulture() returns true if the culture is valid');
$t->is($c->validCulture('fr_FR'), true, '->validCulture() returns true if the culture is valid');
foreach (array('xxx', 'pp', 'frFR') as $culture) {
    $t->is($c->validCulture($culture), false, '->validCulture() returns false if the culture does not exist');
}
// ::getCultures()
$t->diag('::getCultures()');
$cultures = sfCultureInfo::getCultures();
$t->is(in_array('fr', $cultures), true, '::getCultures() returns an array of all available cultures');
$t->is(in_array('fr_FR', $cultures), true, '::getCultures() returns an array of all available cultures');
开发者ID:valerio-bozzolan,项目名称:openparlamento,代码行数:31,代码来源:sfCultureInfoTest.php


注:本文中的sfCultureInfo::getTimeZones方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。