本文整理汇总了PHP中timezone_name_from_abbr函数的典型用法代码示例。如果您正苦于以下问题:PHP timezone_name_from_abbr函数的具体用法?PHP timezone_name_from_abbr怎么用?PHP timezone_name_from_abbr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了timezone_name_from_abbr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_local_timezone
public static function get_local_timezone($reset = FALSE)
{
if ($reset) {
self::$local_timezone = NULL;
}
if (!isset(self::$local_timezone)) {
$tzstring = get_option('timezone_string');
if (empty($tzstring)) {
$gmt_offset = get_option('gmt_offset');
if ($gmt_offset == 0) {
$tzstring = 'UTC';
} else {
$gmt_offset *= HOUR_IN_SECONDS;
$tzstring = timezone_name_from_abbr('', $gmt_offset);
if (false === $tzstring) {
$is_dst = date('I');
foreach (timezone_abbreviations_list() as $abbr) {
foreach ($abbr as $city) {
if ($city['dst'] == $is_dst && $city['offset'] == $gmt_offset) {
$tzstring = $city['timezone_id'];
break 2;
}
}
}
}
if (false === $tzstring) {
$tzstring = 'UTC';
}
}
}
self::$local_timezone = new DateTimeZone($tzstring);
}
return self::$local_timezone;
}
示例2: getTimeZonesArray
static function getTimeZonesArray($choose_one = null)
{
$timezones = array();
if (function_exists("timezone_name_from_abbr")) {
if (!is_null($choose_one)) {
$timezones[null] = $choose_one;
}
for ($x = -12; $x <= 14; $x++) {
$tz_name = timezone_name_from_abbr("", $x * 60 * 60, 0);
if ($tz_name != "") {
$timezones[$tz_name] = "[GMT";
if ($x > 0) {
$timezones[$tz_name] .= " +" . $x;
} elseif ($x < 0) {
$timezones[$tz_name] .= " " . $x;
}
$timezones[$tz_name] .= "] ";
$timezones[$tz_name] .= str_replace("_", " ", $tz_name);
}
}
} else {
$timezones = array('Pacific/Apia' => '[GMT -11] Pacific/Apia', 'Pacific/Honolulu' => '[GMT -10] Pacific/Honolulu', 'America/Anchorage' => '[GMT -9] America/Anchorage', 'America/Los_Angeles' => '[GMT -8] America/Los Angeles', 'America/Denver' => '[GMT -7] America/Denver', 'America/Chicago' => '[GMT -6] America/Chicago', 'America/New_York' => '[GMT -5] America/New York', 'America/Halifax' => '[GMT -4] America/Halifax', 'America/Sao_Paulo' => '[GMT -3] America/Sao Paulo', 'Atlantic/Azores' => '[GMT -1] Atlantic/Azores', 'Europe/London' => '[GMT] Europe/London', 'Europe/Paris' => '[GMT +1] Europe/Paris', 'Europe/Helsinki' => '[GMT +2] Europe/Helsinki', 'Europe/Moscow' => '[GMT +3] Europe/Moscow', 'Asia/Dubai' => '[GMT +4] Asia/Dubai', 'Asia/Karachi' => '[GMT +5] Asia/Karachi', 'Asia/Krasnoyarsk' => '[GMT +7] Asia/Krasnoyarsk', 'Asia/Tokyo' => '[GMT +9] Asia/Tokyo', 'Australia/Melbourne' => '[GMT +10] Australia/Melbourne', 'Pacific/Auckland' => '[GMT +12] Pacific/Auckland');
}
return $timezones;
}
示例3: diff
/** Diff two date objects. Only full units are returned */
public static function diff(TimeInterval $interval, Date $date1, Date $date2) : int
{
if ($date1->getOffsetInSeconds() != $date2->getOffsetInSeconds()) {
// Convert date2 to same timezone as date1. To work around PHP bug #45038,
// not just take the timezone of date1, but construct a new one which will
// have a timezone ID - which is required for this kind of computation.
$tz = new TimeZone(timezone_name_from_abbr('', $date1->getOffsetInSeconds(), $date1->toString('I')));
// Now, convert both dates to the same time (actually we only need to convert the
// second one, as the first will remain in the same timezone)
$date2 = $tz->translate($date2);
}
// Then cut off timezone, by setting both to GMT
$date1 = DateUtil::setTimeZone($date1, new TimeZone('GMT'));
$date2 = DateUtil::setTimeZone($date2, new TimeZone('GMT'));
switch ($interval) {
case TimeInterval::$YEAR:
return -($date1->getYear() - $date2->getYear());
case TimeInterval::$MONTH:
return -(($date1->getYear() - $date2->getYear()) * 12 + ($date1->getMonth() - $date2->getMonth()));
case TimeInterval::$DAY:
return -(intval($date1->getTime() / 86400) - intval($date2->getTime() / 86400));
case TimeInterval::$HOURS:
return -(intval($date1->getTime() / 3600) - intval($date2->getTime() / 3600));
case TimeInterval::$MINUTES:
return -(intval($date1->getTime() / 60) - intval($date2->getTime() / 60));
case TimeInterval::$SECONDS:
return -($date1->getTime() - $date2->getTime());
}
}
示例4: determine_timezone_string
/**
* Returns the timezone string for a site, even if it's set to a UTC offset
*
* Adapted from http://www.php.net/manual/en/function.timezone-name-from-abbr.php#89155
*
* @return string valid PHP timezone string
*/
private function determine_timezone_string()
{
// If site timezone string exists, return it.
if ($timezone = get_option('timezone_string')) {
return $timezone;
}
// Get UTC offset, if it isn't set then return UTC.
if (0 === ($utc_offset = get_option('gmt_offset', 0))) {
return 'UTC';
}
// Adjust UTC offset from hours to seconds.
$utc_offset *= HOUR_IN_SECONDS;
// Attempt to guess the timezone string from the UTC offset.
$timezone = timezone_name_from_abbr('', $utc_offset);
// Last try, guess timezone string manually.
if (false === $timezone) {
$is_dst = date('I');
foreach (timezone_abbreviations_list() as $abbr) {
foreach ($abbr as $city) {
if ($city['dst'] == $is_dst && $city['offset'] == $utc_offset) {
return $city['timezone_id'];
}
}
}
}
// Fallback to UTC.
return 'UTC';
}
示例5: charitable_get_timezone_id
/**
* Retrieve the timezone id.
*
* Credit: Pippin Williamson & the rest of the EDD team.
*
* @return string
* @since 1.0.0
*/
function charitable_get_timezone_id()
{
$timezone = get_option('timezone_string');
/* If site timezone string exists, return it */
if ($timezone) {
return $timezone;
}
$utc_offset = 3600 * get_option('gmt_offset', 0);
/* Get UTC offset, if it isn't set return UTC */
if (!$utc_offset) {
return 'UTC';
}
/* Attempt to guess the timezone string from the UTC offset */
$timezone = timezone_name_from_abbr('', $utc_offset);
/* Last try, guess timezone string manually */
if ($timezone === false) {
$is_dst = date('I');
foreach (timezone_abbreviations_list() as $abbr) {
foreach ($abbr as $city) {
if ($city['dst'] == $is_dst && $city['offset'] == $utc_offset) {
return $city['timezone_id'];
}
}
}
}
/* If we still haven't figured out the timezone, fall back to UTC */
return 'UTC';
}
示例6: get_timezone_id
public static function get_timezone_id()
{
// if site timezone string exists, return it
if ($timezone = get_option('timezone_string')) {
return $timezone;
}
// get UTC offset, if it isn't set return UTC
if (!($utc_offset = 3600 * get_option('gmt_offset', 0))) {
return 'UTC';
}
// attempt to guess the timezone string from the UTC offset
$timezone = timezone_name_from_abbr('', $utc_offset);
// last try, guess timezone string manually
if (FALSE === $timezone) {
$is_dst = date('I');
foreach (timezone_abbreviations_list() as $abbr) {
foreach ($abbr as $city) {
if ($city['dst'] == $is_dst && $city['offset'] == $utc_offset) {
return $city['timezone_id'];
}
}
}
}
return 'UTC';
// fallback
}
示例7: wp_get_timezone_string
/**
* Returns the timezone string for a site, even if it's set to a UTC offset
*
* Adapted from http://www.php.net/manual/en/function.timezone-name-from-abbr.php#89155
*
* @return string valid PHP timezone string
*/
private static function wp_get_timezone_string()
{
$blog_timezone = get_option('timezone_string');
$blog_gmt_offset = get_option('gmt_offset', 0);
// if site timezone string exists, return it
if ($timezone = $blog_timezone) {
return $timezone;
}
// get UTC offset, if it isn't set then return UTC
if (0 === ($utc_offset = $blog_gmt_offset)) {
return 'UTC';
}
// adjust UTC offset from hours to seconds
$utc_offset *= 3600;
// attempt to guess the timezone string from the UTC offset
if ($timezone = timezone_name_from_abbr('', $utc_offset, 0)) {
return $timezone;
}
// last try, guess timezone string manually
$is_dst = date('I');
foreach (timezone_abbreviations_list() as $abbr) {
foreach ($abbr as $city) {
if ($city['dst'] == $is_dst && $city['offset'] == $utc_offset) {
return $city['timezone_id'];
}
}
}
// fallback to UTC
return 'UTC';
}
示例8: getTimezone
/**
* Return DateTimeZone name.
*
* @param int $offset
* @return string timezone name.
*/
public static function getTimezone($offset = 0)
{
$name = timezone_name_from_abbr(null, $offset * 3600, true);
if ($name === false) {
$name = timezone_name_from_abbr(null, $offset * 3600, false);
}
return $name;
}
示例9: getTimezoneValue
public static function getTimezoneValue($offset, $format = 'e')
{
if (!$offset) {
$offset = '+00:00';
}
$t1 = \DateTime::createFromFormat($format, $offset);
return timezone_name_from_abbr($t1->format('T'), $t1->format('Z'), -0);
}
示例10: timezoneOffsetSecondsToTimezoneName
public static function timezoneOffsetSecondsToTimezoneName($seconds)
{
$timezoneAbbreviation = timezone_name_from_abbr('', $seconds, 1);
if ($timezoneAbbreviation === false) {
$timezoneAbbreviation = timezone_name_from_abbr('', $seconds, 0);
}
return $timezoneAbbreviation;
}
示例11: setTimezoneByOffset
function setTimezoneByOffset($offset)
{
$is_DST = FALSE;
// observing daylight savings?
$timezone_name = timezone_name_from_abbr('', $offset * 3600, $is_DST);
// e.g. "America/New_York"
date_default_timezone_set($timezone_name);
}
示例12: getTimezone
/**
* Retrieve a JSON object containing a time zone name given a timezone
* abbreviation.
*
* @param string $abbreviation
* Time zone abbreviation.
* @param int $offset
* Offset from GMT in seconds. Defaults to -1 which means that first found
* time zone corresponding to abbr is returned. Otherwise exact offset is
* searched and only if not found then the first time zone with any offset
* is returned.
* @param null|bool $is_daylight_saving_time
* Daylight saving time indicator. If abbr does not exist then the time
* zone is searched solely by offset and isdst.
*
* @return JsonResponse
* The timezone name in JsonResponse object.
*/
public function getTimezone($abbreviation = '', $offset = -1, $is_daylight_saving_time = NULL)
{
// An abbreviation of "0" passed in the callback arguments should be
// interpreted as the empty string.
$abbreviation = $abbreviation ? $abbreviation : '';
$timezone = timezone_name_from_abbr($abbreviation, intval($offset), $is_daylight_saving_time);
return new JsonResponse($timezone);
}
示例13: createUser
public static function createUser(array $data, array $provider, array $externalToken, array $externalVisitor, XenForo_Model_UserExternal $userExternalModel)
{
$user = null;
/** @var bdApiConsumer_XenForo_Model_UserExternal $userExternalModel */
$options = XenForo_Application::get('options');
/** @var XenForo_DataWriter_User $writer */
$writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
if ($options->registrationDefaults) {
$writer->bulkSet($options->registrationDefaults, array('ignoreInvalidFields' => true));
}
if (!isset($data['timezone']) and isset($externalVisitor['user_timezone_offset'])) {
$tzOffset = $externalVisitor['user_timezone_offset'];
$tzName = timezone_name_from_abbr('', $tzOffset, 1);
if ($tzName !== false) {
$data['timezone'] = $tzName;
}
}
if (!empty($data['user_id'])) {
$writer->setImportMode(true);
}
$writer->bulkSet($data);
if (!empty($data['user_id'])) {
$writer->setImportMode(false);
}
$writer->set('email', $externalVisitor['user_email']);
if (!empty($externalVisitor['user_gender'])) {
$writer->set('gender', $externalVisitor['user_gender']);
}
if (!empty($externalVisitor['user_dob_day']) && !empty($externalVisitor['user_dob_month']) && !empty($externalVisitor['user_dob_year'])) {
$writer->set('dob_day', $externalVisitor['user_dob_day']);
$writer->set('dob_month', $externalVisitor['user_dob_month']);
$writer->set('dob_year', $externalVisitor['user_dob_year']);
}
if (!empty($externalVisitor['user_register_date'])) {
$writer->set('register_date', $externalVisitor['user_register_date']);
}
$userExternalModel->bdApiConsumer_syncUpOnRegistration($writer, $externalToken, $externalVisitor);
$auth = XenForo_Authentication_Abstract::create('XenForo_Authentication_NoPassword');
$writer->set('scheme_class', $auth->getClassName());
$writer->set('data', $auth->generate(''), 'xf_user_authenticate');
$writer->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId);
$writer->set('language_id', XenForo_Visitor::getInstance()->get('language_id'));
$writer->advanceRegistrationUserState(false);
// TODO: option for extra user group
$writer->preSave();
if ($writer->hasErrors()) {
return $user;
}
try {
$writer->save();
$user = $writer->getMergedData();
$userExternalModel->bdApiConsumer_updateExternalAuthAssociation($provider, $externalVisitor['user_id'], $user['user_id'], array_merge($externalVisitor, array('token' => $externalToken)));
XenForo_Model_Ip::log($user['user_id'], 'user', $user['user_id'], 'register_api_consumer');
} catch (XenForo_Exception $e) {
XenForo_Error::logException($e, false);
}
return $user;
}
示例14: convert_utc_offset_abbr
function convert_utc_offset_abbr($offset)
{
$timezone = (int) preg_replace('/[^0-9]/', '', $offset);
$tz = timezone_name_from_abbr(NULL, $timezone * 3600, TRUE);
if ($tz === FALSE) {
$tz = timezone_name_from_abbr(NULL, $offset * 3600, FALSE);
}
return (string) $tz;
}
示例15: setTimezoneOffset
/**
* Set default timezone using offset seconds
*/
public function setTimezoneOffset($offset = 0, $dlst = false)
{
$offset = intval($offset);
if ($timezone = @timezone_name_from_abbr("", $offset, $dlst)) {
$this->timezone = $timezone;
$this->offset = $offset;
return @date_default_timezone_set($timezone);
}
return false;
}