本文整理汇总了PHP中timezone_transitions_get函数的典型用法代码示例。如果您正苦于以下问题:PHP timezone_transitions_get函数的具体用法?PHP timezone_transitions_get怎么用?PHP timezone_transitions_get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了timezone_transitions_get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: previous
/**
* Seek to the previous timezone transition
*
* @throws lang.IllegalArgumentException if timezone has no transitions
*/
public function previous()
{
$ts = $this->date->getTime();
foreach (timezone_transitions_get($this->tz->getHandle()) as $t) {
if ($t['ts'] >= $ts) {
break;
}
$last = $t;
}
if (!isset($t)) {
throw new IllegalArgumentException('Timezone ' . $this->tz->getName() . ' does not have DST transitions.');
}
$this->date = new Date($last['ts'], $this->date->getTimeZone());
$this->isDst = $last['isdst'];
$this->offset = $last['offset'];
$this->abbr = $last['abbr'];
}
示例2: magic2
/**
* The magic function that does everything.
*
**/
function magic2()
{
if (!in_array($this->tz_file, $this->valid_names)) {
trigger_error(sprintf('Bad timezone name given: %s', $this->tz_file), E_USER_ERROR);
}
// TODO: move msg to lang
$tz_obj = timezone_open($this->tz_file);
$tz_data = timezone_transitions_get($tz_obj);
$last = reset($tz_data);
$now = time();
foreach ($tz_data as $transition) {
if ($transition['ts'] > $now) {
$this->gmt_offset = $last['offset'];
$this->abba = $last['abbr'];
$this->next_update = $transition['ts'];
return;
} else {
$last = $transition;
}
}
// default to the last entry if we get here
$this->gmt_offset = $last['offset'];
$this->abba = $last['abbr'];
}
示例3: timezone_select_input
/**
* @access public
* @param string $timezone_string
*/
public static function timezone_select_input($timezone_string = '')
{
// get WP date time format
$datetime_format = get_option('date_format') . ' ' . get_option('time_format');
// if passed a value, then use that, else get WP option
$timezone_string = !empty($timezone_string) ? $timezone_string : get_option('timezone_string');
// check if the timezone is valid but don't throw any errors if it isn't
$timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false);
$gmt_offset = get_option('gmt_offset');
$check_zone_info = true;
if (empty($timezone_string)) {
// Create a UTC+- zone if no timezone string exists
$check_zone_info = false;
if ($gmt_offset > 0) {
$timezone_string = 'UTC+' . $gmt_offset;
} elseif ($gmt_offset < 0) {
$timezone_string = 'UTC' . $gmt_offset;
} else {
$timezone_string = 'UTC';
}
}
?>
<p>
<label for="timezone_string"><?php
_e('timezone');
?>
</label>
<select id="timezone_string" name="timezone_string">
<?php
echo wp_timezone_choice($timezone_string);
?>
</select>
<br />
<span class="description"><?php
_e('Choose a city in the same timezone as the event.');
?>
</span>
</p>
<p>
<span><?php
printf(__('%1$sUTC%2$s time is %3$s'), '<abbr title="Coordinated Universal Time">', '</abbr>', '<code>' . date_i18n($datetime_format, false, 'gmt') . '</code>');
?>
</span>
<?php
if (!empty($timezone_string) || !empty($gmt_offset)) {
?>
<br /><span><?php
printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>');
?>
</span>
<?php
}
?>
<?php
if ($check_zone_info && $timezone_string) {
?>
<br />
<span>
<?php
// Set TZ so localtime works.
date_default_timezone_set($timezone_string);
$now = localtime(time(), true);
if ($now['tm_isdst']) {
_e('This timezone is currently in daylight saving time.');
} else {
_e('This timezone is currently in standard time.');
}
?>
<br />
<?php
if (function_exists('timezone_transitions_get')) {
$found = false;
$date_time_zone_selected = new DateTimeZone($timezone_string);
$tz_offset = timezone_offset_get($date_time_zone_selected, date_create());
$right_now = time();
$tr['isdst'] = false;
foreach (timezone_transitions_get($date_time_zone_selected) as $tr) {
if ($tr['ts'] > $right_now) {
$found = true;
break;
}
}
if ($found) {
$message = $tr['isdst'] ? __(' Daylight saving time begins on: %s.') : __(' Standard time begins on: %s.');
// Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n().
printf($message, '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >');
} else {
_e('This timezone does not observe daylight saving time.');
}
}
// Set back to UTC.
date_default_timezone_set('UTC');
?>
//.........这里部分代码省略.........
示例4: var_dump
var_dump(date_format($dt, 'Y-m-d H:i:s'));
var_dump(timezone_name_from_abbr("CET"));
var_dump(timezone_name_from_abbr("", 3600, 0));
$tz = timezone_open("Asia/Shanghai");
var_dump(timezone_name_get($tz));
// Create two timezone objects, one for Taipei (Taiwan) and one for
// Tokyo (Japan)
$dateTimeZoneTaipei = timezone_open("Asia/Taipei");
$dateTimeZoneJapan = timezone_open("Asia/Tokyo");
// Create two DateTime objects that will contain the same Unix timestamp, but
// have different timezones attached to them.
$dateTimeTaipei = date_create("2008-08-08", $dateTimeZoneTaipei);
$dateTimeJapan = date_create("2008-08-08", $dateTimeZoneJapan);
var_dump(date_offset_get($dateTimeTaipei));
var_dump(date_offset_get($dateTimeJapan));
$tz = timezone_open("Asia/Shanghai");
var_dump(timezone_name_get($tz));
$timezone = timezone_open("CET");
$transitions = timezone_transitions_get($timezone);
var_dump($transitions[0]['ts']);
var_dump($transitions[0]['offset']);
var_dump($transitions[0]['isdst']);
var_dump($transitions[0]['abbr']);
$tz = timezone_open("EDT");
var_dump(timezone_name_get($tz));
$tz = timezone_open("PST");
var_dump(timezone_name_get($tz));
$tz = timezone_open("CHAST");
var_dump(timezone_name_get($tz));
var_dump((bool) timezone_version_get());
var_dump(timezone_open('sdf'));
示例5: __toString
// define some classes
class classWithToString
{
public function __toString()
{
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// add arrays
$index_array = array(1, 2, 3);
$assoc_array = array('one' => 1, 'two' => 2);
// resource
$file_handle = fopen(__FILE__, 'r');
//array of values to iterate over
$inputs = array('int 0' => 0, 'int 1' => 1, 'int 12345' => 12345, 'int -12345' => -12345, 'float 10.5' => 10.5, 'float -10.5' => -10.5, 'float .5' => 0.5, 'empty array' => array(), 'int indexed array' => $index_array, 'associative array' => $assoc_array, 'nested arrays' => array('foo', $index_array, $assoc_array), 'uppercase NULL' => NULL, 'lowercase null' => null, 'lowercase true' => true, 'lowercase false' => false, 'uppercase TRUE' => TRUE, 'uppercase FALSE' => FALSE, 'empty string DQ' => "", 'empty string SQ' => '', 'string DQ' => "string", 'string SQ' => 'string', 'mixed case string' => "sTrInG", 'heredoc' => $heredoc, 'instance of classWithToString' => new classWithToString(), 'instance of classWithoutToString' => new classWithoutToString(), 'undefined var' => @$undefined_var, 'unset var' => @$unset_var, 'resource' => $file_handle);
foreach ($inputs as $variation => $object) {
echo "\n-- {$variation} --\n";
var_dump(timezone_transitions_get($object));
}
// closing the resource
fclose($file_handle);
?>
===DONE===
示例6: eventespresso_ddtimezone
function eventespresso_ddtimezone($event_id = 0)
{
global $wpdb;
$tz_event = $wpdb->get_var($wpdb->prepare("SELECT timezone_string FROM " . EVENTS_DETAIL_TABLE . " WHERE id = '" . $event_id . "'"));
$timezone_format = _x('Y-m-d G:i:s', 'timezone date format');
$current_offset = get_option('gmt_offset');
$tzstring = $tz_event != '' ? $tz_event : get_option('timezone_string');
//echo $tzstring;
$check_zone_info = true;
// Remove old Etc mappings. Fallback to gmt_offset.
if (false !== strpos($tzstring, 'Etc/GMT')) {
$tzstring = '';
}
if (empty($tzstring)) {
// Create a UTC+- zone if no timezone string exists
$check_zone_info = false;
if (0 == $current_offset) {
$tzstring = 'UTC+0';
} elseif ($current_offset < 0) {
$tzstring = 'UTC' . $current_offset;
} else {
$tzstring = 'UTC+' . $current_offset;
}
}
?>
<p><select id="timezone_string" name="timezone_string">
<?php
echo wp_timezone_choice($tzstring);
?>
</select>
<br />
<span class="description"><?php
_e('Choose a city in the same timezone as the event.');
?>
</span>
</p>
<p><span><?php
printf(__('<abbr title="Coordinated Universal Time">UTC</abbr> time is <code>%s</code>'), date_i18n($timezone_format, false, 'gmt'));
?>
</span>
<?php
if (get_option('timezone_string') || !empty($current_offset)) {
?>
<br /><span><?php
printf(__('Local time is <code>%1$s</code>'), date_i18n($timezone_format));
?>
</span>
<?php
}
?>
<?php
if ($check_zone_info && $tzstring) {
?>
<br />
<span>
<?php
// Set TZ so localtime works.
date_default_timezone_set($tzstring);
$now = localtime(time(), true);
if ($now['tm_isdst']) {
_e('This timezone is currently in daylight saving time.');
} else {
_e('This timezone is currently in standard time.');
}
?>
<br />
<?php
if (function_exists('timezone_transitions_get')) {
$found = false;
$date_time_zone_selected = new DateTimeZone($tzstring);
$tz_offset = timezone_offset_get($date_time_zone_selected, date_create());
$right_now = time();
foreach (timezone_transitions_get($date_time_zone_selected) as $tr) {
if ($tr['ts'] > $right_now) {
$found = true;
break;
}
}
if ($found) {
echo ' ';
$message = $tr['isdst'] ? __('Daylight saving time begins on: <code>%s</code>.') : __('Standard time begins on: <code>%s</code>.');
// Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n().
printf($message, date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $tr['ts'] + ($tz_offset - $tr['offset'])));
} else {
_e('This timezone does not observe daylight saving time.');
}
}
// Set back to UTC.
date_default_timezone_set('UTC');
?>
</span></p>
<?php
}
}
示例7: date_default_timezone_set
<?php
/* Prototype : array timezone_transitions_get ( DateTimeZone $object, [ int $timestamp_begin [, int $timestamp_end ]] )
* Description: Returns all transitions for the timezone
* Source code: ext/date/php_date.c
* Alias to functions: DateTimeZone::getTransitions()
*/
//Set the default time zone
date_default_timezone_set("GMT");
$tz = timezone_open("Europe/London");
echo "*** Testing timezone_transitions_get() : error conditions ***\n";
echo "\n-- Testing timezone_transitions_get() function with zero arguments --\n";
var_dump(timezone_transitions_get());
echo "\n-- Testing timezone_transitions_get() function with more than expected no. of arguments --\n";
$timestamp_begin = mktime(0, 0, 0, 1, 1, 1972);
$timestamp_end = mktime(0, 0, 0, 1, 1, 1975);
$extra_arg = 99;
var_dump(timezone_transitions_get($tz, $timestamp_begin, $timestamp_end, $extra_arg));
echo "\n-- Testing timezone_transitions_get() function with an invalid values for \$object argument --\n";
$invalid_obj = new stdClass();
var_dump(timezone_transitions_get($invalid_obj));
$invalid_obj = 10;
var_dump(timezone_transitions_get($invalid_obj));
$invalid_obj = null;
var_dump(timezone_transitions_get($invalid_obj));
?>
===DONE===
示例8: hasDst
/**
* Retrieve whether the timezone does have DST/non-DST mode
*
* @return bool
*/
public function hasDst()
{
return (bool) sizeof(timezone_transitions_get($this->tz));
}
示例9: cets_blog_defaults_management_page
function cets_blog_defaults_management_page(){
// Display the defaults that can be set by site admins
global $wpdb;
// only allow site admins to come here.
if( is_super_admin() == false ) {
wp_die( __('You do not have permission to access this page.') );
}
/* translators: date and time format for exact current time, mainly about timezones, see http://php.net/date */
$timezone_format = _x('Y-m-d G:i:s', 'timezone date format');
// process form submission
if (isset($_POST['action']) && $_POST['action'] == 'update') {
$this->update_defaults($_POST);
$updated = true;
}
// make sure we're using latest data
$opt = get_site_option('cets_blog_defaults_options');
if (isset($updated) && $updated) { ?>
<div id="message" class="updated fade"><p><?php _e('Options saved.') ?></p></div>
<?php } ?>
<h1>New Blog Defaults</h1>
<form name="blogdefaultsform" action="" method="post">
<p>Set the defaults for new blog creation. Note that these defaults can still be over-ridden by blog owners.</p>
<div class="wrap">
<h2><?php _e('General Settings') ?></h2>
<table class="form-table">
<tr valign="top">
<th scope="row"><?php _e('Blog Title') ?></th>
<td><input name="blogname" type="text" id="blogname" value="<?php echo($opt['blogname']); ?>" size="40" /><br/>
<input type="checkbox" name="blogname_flag" value="1" <?php checked('1', $opt[blogname_flag]) ?> /> <?php _e("I understand this will overwrite the user's chosen blog name from the setup page.") ?></td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Tagline') ?></th>
<td><input name="blogdescription" type="text" id="blogdescription" style="width: 95%" value="<?php echo($opt['blogdescription']); ?>" size="45" />
<br />
<?php _e('In a few words, explain what this blog is about.') ?></td>
</tr>
<!-- Begin Time Zone -->
<tr>
<?php
$current_offset = $opt['gmt_offset'];
$tzstring = $opt['timezone_string'];
$check_zone_info = true;
// Remove old Etc mappings. Fallback to gmt_offset.
if ( false !== strpos($tzstring,'Etc/GMT') )
$tzstring = '';
if (empty($tzstring)) { // set the Etc zone if no timezone string exists
$check_zone_info = false;
if ( 0 == $current_offset )
$tzstring = 'UTC+0';
elseif ($current_offset < 0)
$tzstring = 'UTC' . $current_offset;
else
$tzstring = 'UTC+' . $current_offset;
}
?>
<th scope="row"><label for="timezone_string"><?php _e('Timezone') ?></label></th>
<td>
<select id="timezone_string" name="timezone_string">
<?php echo wp_timezone_choice($tzstring); ?>
</select>
<span id="utc-time"><?php printf(__('<abbr title="Coordinated Universal Time">UTC</abbr> time is <code>%s</code>'), date_i18n($timezone_format, false, 'gmt')); ?></span>
<?php if ($opt['timezone_string']) : ?>
<span id="local-time"><?php printf(__('Local time is <code>%1$s</code>'), date_i18n($timezone_format)); ?></span>
<?php endif; ?>
<br />
<span class="description"><?php _e('Choose a city in the same timezone as you.'); ?></span>
<br />
<span>
<?php if ($check_zone_info && $tzstring) : ?>
<?php
$now = localtime(time(),true);
if ($now['tm_isdst']) _e('This timezone is currently in daylight savings time.');
else _e('This timezone is currently in standard time.');
?>
<br />
<?php
if (function_exists('timezone_transitions_get')) {
$dateTimeZoneSelected = new DateTimeZone($tzstring);
foreach (timezone_transitions_get($dateTimeZoneSelected) as $tr) {
if ($tr['ts'] > time()) {
$found = true;
break;
}
}
//.........这里部分代码省略.........
示例10: isDayLightSavingTime
/**
* @param string|DateTimeInterface $value
* @param DateTimeZone $timeZone
* @param string $message
*/
public static function isDayLightSavingTime($value, DateTimeZone $timeZone, $message = '')
{
$value = self::convertToDateTime($value);
$transitions = timezone_transitions_get($timeZone, $value->getTimestamp(), $value->getTimestamp());
if (is_array($transitions) && !empty($transitions)) {
foreach ($transitions as $transition) {
if (0 == $transition['isdst']) {
throw new AssertionException($message ? $message : self::ASSERT_IS_DST);
}
}
}
}
示例11: array
{
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// add arrays
$index_array = array(1, 2, 3);
$assoc_array = array('one' => 1, 'two' => 2);
// resource
$file_handle = fopen(__FILE__, 'r');
//array of values to iterate over
$inputs = array('int 0' => 0, 'int 1' => 1, 'int 12345' => 12345, 'int -12345' => -12345, 'float 10.5' => 10.5, 'float -10.5' => -10.5, 'float .5' => 0.5, 'empty array' => array(), 'int indexed array' => $index_array, 'associative array' => $assoc_array, 'nested arrays' => array('foo', $index_array, $assoc_array), 'uppercase NULL' => NULL, 'lowercase null' => null, 'lowercase true' => true, 'lowercase false' => false, 'uppercase TRUE' => TRUE, 'uppercase FALSE' => FALSE, 'empty string DQ' => "", 'empty string SQ' => '', 'string DQ' => "string", 'string SQ' => 'string', 'mixed case string' => "sTrInG", 'heredoc' => $heredoc, 'instance of classWithToString' => new classWithToString(), 'instance of classWithoutToString' => new classWithoutToString(), 'undefined var' => @$undefined_var, 'unset var' => @$unset_var, 'resource' => $file_handle);
$tz = timezone_open("Europe/London");
$timestamp_end = mktime(0, 0, 0, 1, 1, 1975);
foreach ($inputs as $variation => $timestamp_begin) {
echo "\n-- {$variation} --\n";
$tran = timezone_transitions_get($tz, $timestamp_begin, $timestamp_end);
var_dump(gettype($tran));
var_dump(count($tran));
}
// closing the resource
fclose($file_handle);
?>
===DONE===
示例12: timezone_transitions_get
<?php
/* Prototype : array timezone_transitions_get ( DateTimeZone $object, [ int $timestamp_begin [, int $timestamp_end ]] )
* Description: Returns all transitions for the timezone
* Source code: ext/date/php_date.c
* Alias to functions: DateTimeZone::getTransitions()
*/
echo "*** Testing timezone_transitions_get() : basic functionality ***\n";
//Set the default time zone
date_default_timezone_set("Europe/London");
// Create a DateTimeZone object
$tz = timezone_open("Europe/London");
$tran = timezone_transitions_get($tz);
echo "\n-- Get all 60s transitions --\n";
$tran = timezone_transitions_get($tz, -306972000, -37241999);
var_dump(gettype($tran));
echo "\n-- Total number of transitions: " . count($tran) . " --\n";
echo "\n-- Format a sample entry pfor Spring 1963 --\n";
var_dump($tran[6]);
?>
===DONE===
示例13: localtime
<?php
if ($tzstring) {
?>
<?php
$now = localtime(time(), true);
if ($now['tm_isdst']) {
_e('This timezone is currently in daylight savings time.');
} else {
_e('This timezone is currently in standard time.');
}
?>
<br />
<?php
if (function_exists('timezone_transitions_get')) {
$dateTimeZoneSelected = new DateTimeZone($tzstring);
foreach (timezone_transitions_get($dateTimeZoneSelected) as $tr) {
if ($tr['ts'] > time()) {
$found = true;
break;
}
}
if (isset($found) && $found === true) {
echo ' ';
$message = $tr['isdst'] ? __('Daylight savings time begins on: <code>%s</code>.') : __('Standard time begins on: <code>%s</code>.');
printf($message, date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $tr['ts']));
} else {
_e('This timezone does not observe daylight savings time.');
}
}
?>
</span>
示例14: abs
$timezone_string = 'Etc/GMT+' . abs($_gmt_offset);
}
unset($_gmt_offset);
}
// Build the new selector
$_time_options = array('timezone_string' => array('title' => __('Time zone'), 'type' => 'select', 'options' => wp_timezone_choice($timezone_string), 'note' => array(__('Choose a city in the same time zone as you.'), sprintf(__('<abbr title="Coordinated Universal Time">UTC</abbr> time is <code>%s</code>'), bb_gmdate_i18n(bb_get_datetime_formatstring_i18n(), bb_current_time())), sprintf(__('Local time is <code>%s</code>'), bb_datetime_format_i18n(bb_current_time())))));
$_now = localtime(bb_current_time(), true);
if ($now['tm_isdst']) {
$_time_options['timezone_string']['note'][] = __('This time zone is currently in daylight savings time.');
} else {
$_time_options['timezone_string']['note'][] = __('This time zone is currently in standard time.');
}
if (function_exists('timezone_transitions_get')) {
$timezone_object = new DateTimeZone($timezone_string);
$found_transition = false;
foreach (timezone_transitions_get($timezone_object) as $timezone_transition) {
if ($timezone_transition['ts'] > time()) {
$note = $timezone_transition['isdst'] ? __('Daylight savings time begins on <code>%s</code>') : __('Standard time begins on <code>%s</code>');
$_time_options['timezone_string']['note'][] = sprintf($note, bb_gmdate_i18n(bb_get_datetime_formatstring_i18n(), $timezone_transition['ts'], false));
break;
}
}
}
$time_options = array_merge($_time_options, $time_options);
} else {
// Tidy up the old style dropdown
$time_options['gmt_offset']['note'] = array(1 => sprintf(__('<abbr title="Coordinated Universal Time">UTC</abbr> %s is <code>%s</code>'), $time_options['gmt_offset']['options'][$gmt_offset], bb_datetime_format_i18n(bb_current_time())), 2 => __('Unfortunately, you have to manually update this for Daylight Savings Time.'));
if ($gmt_offset) {
$time_options['gmt_offset']['note'][0] = sprintf(__('<abbr title="Coordinated Universal Time">UTC</abbr> time is <code>%s</code>'), bb_gmdate_i18n(bb_get_datetime_formatstring_i18n(), bb_current_time(), true));
ksort($time_options['gmt_offset']['note']);
}
示例15: localtime
$now = localtime(time(), true);
if ($now['tm_isdst']) {
_e('This timezone is currently in daylight saving time.');
} else {
_e('This timezone is currently in standard time.');
}
?>
<br />
<?php
$allowed_zones = timezone_identifiers_list();
if (in_array($tzstring, $allowed_zones)) {
$found = false;
$date_time_zone_selected = new DateTimeZone($tzstring);
$tz_offset = timezone_offset_get($date_time_zone_selected, date_create());
$right_now = time();
foreach (timezone_transitions_get($date_time_zone_selected) as $tr) {
if ($tr['ts'] > $right_now) {
$found = true;
break;
}
}
if ($found) {
echo ' ';
$message = $tr['isdst'] ? __('Daylight saving time begins on: <code>%s</code>.') : __('Standard time begins on: <code>%s</code>.');
// Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n().
printf($message, date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $tr['ts'] + ($tz_offset - $tr['offset'])));
} else {
_e('This timezone does not observe daylight saving time.');
}
}
// Set back to UTC.