本文整理汇总了PHP中timezone_offset_get函数的典型用法代码示例。如果您正苦于以下问题:PHP timezone_offset_get函数的具体用法?PHP timezone_offset_get怎么用?PHP timezone_offset_get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了timezone_offset_get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct()
{
global $wpdb;
if (get_option('timezone_string')) {
$this->tz_offset = timezone_offset_get(timezone_open(get_option('timezone_string')), new DateTime());
} else {
if (get_option('gmt_offset')) {
$this->tz_offset = get_option('gmt_offset') * 60 * 60;
}
}
$this->db = $wpdb;
$this->tb_prefix = $wpdb->prefix;
$this->agent = $this->get_UserAgent();
$this->historical = array();
// Load the options from the database
$this->options = get_option('wp_statistics');
// Set the default co-efficient.
$this->coefficient = $this->get_option('coefficient', 1);
// Double check the co-efficient setting to make sure it's not been set to 0.
if ($this->coefficient <= 0) {
$this->coefficient = 1;
}
// This is a bit of a hack, we strip off the "includes/classes" at the end of the current class file's path.
$this->plugin_dir = substr(dirname(__FILE__), 0, -17);
$this->plugin_url = substr(plugin_dir_url(__FILE__), 0, -17);
$this->get_IP();
if ($this->get_option('hash_ips') == true) {
$this->ip_hash = '#hash#' . sha1($this->ip + $_SERVER['HTTP_USER_AGENT']);
}
}
示例2: getSchedule
/**
* Get weekly shedule for a particular day
*
* @param $timestamp
* @return array
*/
function getSchedule($timestamp)
{
if (!$this->magister->personData) {
return 403;
}
$tz = timezone_open('Europe/Amsterdam');
$tz_offset = timezone_offset_get($tz, new \DateTime('@' . $timestamp, timezone_open('UTC')));
$timestamp += $tz_offset + 4;
$weekstart = $this->getFirstDayOfWeek(date('Y', $timestamp), date('W', $timestamp));
$weekend = strtotime('this Friday', $weekstart);
$data = $this->magister->personRequest('afspraken?status=1&tot=' . date('Y-m-d', $weekend) . '&van=' . date('Y-m-d', $weekstart))->Items;
$result = array('week_timestamp' => $weekstart, 'days' => array());
$curday = $weekstart;
while ($curday <= $weekend) {
$result['days'][(int) date('w', $curday)] = array('day_title' => $this->dutchDayName($curday), 'day_ofweek' => (int) date('w', $curday), 'items' => array());
$curday += 86400;
}
foreach ($data as $item) {
$start = strtotime($item->Start) + $tz_offset;
$curwd = date('w', $start);
if ($item->DuurtHeleDag) {
$result['days'][(int) $curwd]['items'][] = array('title' => $item->Omschrijving, 'subtitle' => $item->Lokatie, 'start' => $start, 'start_str' => 'DAG');
} else {
$result['days'][(int) $curwd]['items'][] = array('title' => $item->LesuurVan . '. ' . $item->Vakken[0]->Naam, 'subtitle' => 'Lokaal ' . $item->Lokalen[0]->Naam, 'start' => $start, 'start_str' => date('H:i', $start + $tz_offset));
}
}
foreach ($result['days'] as $index => $day) {
if (empty($day['items'])) {
unset($result['days'][$index]);
}
}
return $result;
}
示例3: testUsingYiiTimeZoneSwitcherWithPhpTimeFunction
public function testUsingYiiTimeZoneSwitcherWithPhpTimeFunction()
{
$oldTimeZone = Yii::app()->getTimeZone();
$dateTimeUtc = new DateTime();
$timeStamp = time();
//always UTC regardless of server timezone or any timezone setting.
Yii::app()->setTimeZone('UTC');
$dateStamp = date("Y-m-d G:i", $timeStamp);
Yii::app()->setTimeZone('America/Chicago');
$dateStamp2 = date("Y-m-d G:i", $timeStamp);
Yii::app()->setTimeZone('America/New_York');
$timeZoneObject = new DateTimeZone('America/New_York');
$offset = $timeZoneObject->getOffset(new DateTime());
$this->assertTrue($offset == -18000 || $offset == -14400);
$newYorkTimeZone = new DateTimeZone(date_default_timezone_get());
$offset1 = $newYorkTimeZone->getOffset($dateTimeUtc);
$offset2 = timezone_offset_get($newYorkTimeZone, $dateTimeUtc);
$this->assertEquals($offset, $offset1);
$this->assertEquals($offset, $offset2);
if ($offset == -18000) {
$offsetHours = 6;
} else {
$offsetHours = 5;
}
$dateStamp3 = date("Y-m-d G:i", $timeStamp);
$this->assertEquals(strtotime($dateStamp), strtotime($dateStamp2) + 3600 * $offsetHours);
// + 5 from GMT or +6 depending on DST
$this->assertEquals(strtotime($dateStamp3), strtotime($dateStamp2) + 3600 * 1);
// + 1 from NY
//Use retrieved offset based on timezone.
Yii::app()->setTimeZone($oldTimeZone);
}
示例4: __construct
/**
* Constructor. Pass in the global configuration object
*
* @param type $conf
*/
function __construct($conf)
{
$this->load = new Loader();
if (empty($conf)) {
return;
}
$timezone = ini_get('date.timezone');
if (!$timezone) {
$system_timezone = exec('date +%Z');
date_default_timezone_set($system_timezone);
$timezone = date_default_timezone_get();
}
$this->timezone_offset = timezone_offset_get(new DateTimeZone($timezone), new DateTime());
$this->conf = $conf;
$this->data_model = new AnemometerModel($conf);
if (array_key_exists('time_columns', $this->conf)) {
$this->time_columns = $this->conf['time_columns'];
} else {
$this->time_columns = array();
}
$datasource = get_var('datasource');
if (isset($datasource)) {
$this->data_model->set_data_source($datasource);
$this->data_model->connect_to_datasource();
}
$this->init_report();
session_start();
}
示例5: getOffset
private function getOffset($tz)
{
if ($tz == '') {
return 0;
}
# Heure GMT
return timezone_offset_get(new \DateTimeZone($tz), new \DateTime());
}
示例6: format_date
function format_date($format, $timestamp = null)
{
global $timezone;
if ($timestamp == null) {
$timestamp = time();
}
$timestamp = $timestamp + timezone_offset_get(new DateTimeZone($timezone), new DateTime());
return date($format, $timestamp);
}
示例7: testOutreachPunchcardInsight
public function testOutreachPunchcardInsight()
{
$cfg = Config::getInstance();
$install_timezone = new DateTimeZone($cfg->getValue('timezone'));
$owner_timezone = new DateTimeZone($test_timezone = 'America/Los_Angeles');
// Get data ready that insight requires
$posts = self::getTestPostObjects();
$post_pub_date = new DateTime($posts[0]->pub_date);
$now = new DateTime();
$offset = timezone_offset_get($owner_timezone, $now) - timezone_offset_get($install_timezone, $now);
$post_dotw = date('N', date('U', strtotime($posts[0]->pub_date)) + timezone_offset_get($owner_timezone, $now));
$post_hotd = date('G', date('U', strtotime($posts[0]->pub_date)) + timezone_offset_get($owner_timezone, $now));
$builders = array();
$builders[] = FixtureBuilder::build('users', array('user_id' => '7654321', 'user_name' => 'twitteruser', 'full_name' => 'Twitter User', 'avatar' => 'avatar.jpg', 'follower_count' => 36000, 'is_protected' => 0, 'network' => 'twitter', 'description' => 'A test Twitter User'));
$instance_id = 10;
$builders[] = FixtureBuilder::build('owners', array('id' => 1, 'full_name' => 'ThinkUp J. User', 'email' => 'test@example.com', 'is_activated' => 1, 'email_notification_frequency' => 'never', 'is_admin' => 0, 'timezone' => $test_timezone));
$builders[] = FixtureBuilder::build('owner_instances', array('owner_id' => '1', 'instance_id' => $instance_id));
$install_offset = $install_timezone->getOffset(new DateTime());
$date_r = date("Y-m-d", strtotime('-1 day') - $install_offset);
// Response between 1pm and 2pm install time
$time = gmdate('Y-m-d H:i:s', strtotime('yesterday 13:11:09'));
$builders[] = FixtureBuilder::build('posts', array('id' => 136, 'post_id' => 136, 'author_user_id' => 7654321, 'author_username' => 'twitteruser', 'author_fullname' => 'Twitter User', 'author_avatar' => 'avatar.jpg', 'network' => 'twitter', 'post_text' => 'This is a reply.', 'source' => 'web', 'pub_date' => $time, 'in_reply_to_post_id' => 133, 'reply_count_cache' => 0, 'is_protected' => 0));
// Response between 1pm and 2pm install time
$time = gmdate('Y-m-d H:i:s', strtotime('yesterday 13:01:13'));
$builders[] = FixtureBuilder::build('posts', array('id' => 137, 'post_id' => 137, 'author_user_id' => 7654321, 'author_username' => 'twitteruser', 'author_fullname' => 'Twitter User', 'author_avatar' => 'avatar.jpg', 'network' => 'twitter', 'post_text' => 'This is a reply.', 'source' => 'web', 'pub_date' => $time, 'in_reply_to_post_id' => 133, 'reply_count_cache' => 0, 'is_protected' => 0));
// Response between 1pm and 2pm install time
$time = gmdate('Y-m-d H:i:s', strtotime('yesterday 13:13:56'));
$builders[] = FixtureBuilder::build('posts', array('id' => 138, 'post_id' => 138, 'author_user_id' => 7654321, 'author_username' => 'twitteruser', 'author_fullname' => 'Twitter User', 'author_avatar' => 'avatar.jpg', 'network' => 'twitter', 'post_text' => 'This is a reply.', 'source' => 'web', 'pub_date' => $time, 'in_reply_to_post_id' => 135, 'reply_count_cache' => 0, 'is_protected' => 0));
// Response between 11am and 12pm install time
$time = gmdate('Y-m-d H:i:s', strtotime('yesterday 11:07:42'));
$builders[] = FixtureBuilder::build('posts', array('id' => 139, 'post_id' => 139, 'author_user_id' => 7654321, 'author_username' => 'twitteruser', 'author_fullname' => 'Twitter User', 'author_avatar' => 'avatar.jpg', 'network' => 'twitter', 'source' => 'web', 'post_text' => 'RT @testeriffic: New Year\'s Eve! Feeling very gay today, but not very homosexual.', 'pub_date' => $time, 'in_retweet_of_post_id' => 134, 'reply_count_cache' => 0, 'is_protected' => 0));
$time1str_low = date('ga', date('U', strtotime($date_r . ' 13:00:00')) + $offset);
$time1str_high = date('ga', date('U', strtotime($date_r . ' 14:00:00')) + $offset);
$time1str = $time1str_low . " and " . $time1str_high;
$time2str_low = date('ga', date('U', strtotime($date_r . ' 11:00:00')) + $offset);
$time2str_high = date('ga', date('U', strtotime($date_r . ' 12:00:00')) + $offset);
$time2str = $time2str_low . " and " . $time2str_high;
$instance = new Instance();
$instance->id = $instance_id;
$instance->network_username = 'testeriffic';
$instance->network = 'twitter';
$insight_plugin = new OutreachPunchcardInsight();
$insight_plugin->generateInsight($instance, $posts, 3);
// Assert that insight got inserted with correct punchcard information
$insight_dao = new InsightMySQLDAO();
$today = date('Y-m-d');
$result = $insight_dao->getInsight('outreach_punchcard', 10, $today);
$punchcard = unserialize($result->related_data);
$this->debug(Utils::varDumpToString($result));
$this->assertNotNull($result);
$this->assertIsA($result, "Insight");
$this->assertEqual($punchcard['posts'][$post_dotw][$post_hotd], 3);
$this->assertPattern('/\\@testeriffic\'s tweets from last week got/', $result->text);
$this->assertPattern('/<strong>3 responses<\\/strong> between <strong>' . $time1str . '<\\/strong>/', $result->text);
$this->assertPattern('/as compared to <strong>1 response<\\/strong>/', $result->text);
$this->assertPattern('/<strong>1 response<\\/strong> between <strong>' . $time2str . '<\\/strong>/', $result->text);
}
示例8: getOffset
private function getOffset($tz)
{
if ($tz == '') {
// ATTENTION !!!!!!!!!!!!!!!!!!!!!!!!!!!
$tz = 'GMT';
}
if ($tz == 'GMT') {
$offset = 0;
} else {
$offset = timezone_offset_get(new \DateTimeZone($tz), new \DateTime());
}
return $offset;
}
示例9: timezone_offset
/**
* Utility method that returns time string offset by timezone
* @since 1.0.0
* @param string $tzstring Time string
* @return string Offset time string
*/
public function timezone_offset($tzstring)
{
if (!empty($tzstring) && is_string($tzstring)) {
if ('UTC' === substr($tzstring, 0, 3)) {
$tzstring = str_replace(array(':15', ':30', ':45'), array('.25', '.5', '.75'), $tzstring);
return intval(floatval(substr($tzstring, 3)) * HOUR_IN_SECONDS);
}
$date_time_zone_selected = new DateTimeZone($tzstring);
$tz_offset = timezone_offset_get($date_time_zone_selected, date_create());
return $tz_offset;
}
return 0;
}
示例10: zoneInfo
/**
* Return a set of timezone information relevant to this joyful stuff :D
*/
public static function zoneInfo() {
$zones = array();
$now = date_create();
foreach( timezone_identifiers_list() as $tz ) {
$zone = timezone_open( $tz );
$name = timezone_name_get( $zone );
$location = timezone_location_get( $zone );
$offset = timezone_offset_get( $zone, $now ) / 60; // convert seconds to minutes
$zones[] = array('name' => $name, 'offset' => $offset, 'location' => $location);
}
return $zones;
}
示例11: timezone_offset
/**
* Utility method that returns time string offset by timezone
* @since 1.0.0
* @param string $tzstring Time string
* @return string Offset time string
*/
public function timezone_offset($tzstring)
{
$tz_offset = 0;
if (!empty($tzstring) && is_string($tzstring)) {
if ('UTC' === substr($tzstring, 0, 3)) {
$tzstring = str_replace(array(':15', ':30', ':45'), array('.25', '.5', '.75'), $tzstring);
return intval(floatval(substr($tzstring, 3)) * HOUR_IN_SECONDS);
}
try {
$date_time_zone_selected = new DateTimeZone($tzstring);
$tz_offset = timezone_offset_get($date_time_zone_selected, date_create());
} catch (Exception $e) {
$this->log_if_debug(__METHOD__, __LINE__, $e->getMessage());
}
}
return $tz_offset;
}
示例12: init
public function init()
{
parent::init();
$session = Yii::app()->session;
$timezone = $session->get("timezone");
if (is_null($timezone)) {
$timezone = date_default_timezone_get();
}
if (!$this->isValidTimeZone($timezone)) {
$timezone = date_default_timezone_get();
}
$this->timezone = $timezone;
$this->phpTimezone = date_default_timezone_get();
$this->timezoneOffset = timezone_offset_get(new DateTimeZone($this->timezone), new DateTime());
$this->phpTimezoneOffset = timezone_offset_get(new DateTimeZone($this->phpTimezone), new DateTime());
//Yii::log("TimeZoneFix::init timezone=[{$this->timezone}],phpTimezone=[{$this->phpTimezone}],timezoneOffset=[{$this->timezoneOffset}],phpTimezoneOffset=[{$this->phpTimezoneOffset},lan=[".Yii::app()->language."]","info");
}
示例13: exportDataSeriesOptions
protected function exportDataSeriesOptions(Flot\DataSeries $dataSeries)
{
$options = $dataSeries->getOptions();
$data = iterator_to_array($dataSeries->getData());
$options['data'] = array_map(function (Flot\DataValue $value) {
if ($value->key instanceof \DateTime) {
$timestamp = (int) $value->key->format('U') + timezone_offset_get($value->key->getTimezone(), $value->key);
return [$timestamp * 1000, (double) $value->value];
} else {
return [(int) $value->key, (double) $value->value];
}
}, array_values($data));
foreach ($dataSeries->getTypes() as $type) {
$options[$type->getIdentifier()] = $this->exportTypeOptions($type);
}
return $options;
}
示例14: filter
/**
* Filter the supplied input string to an ISO date.
*
* @param string $value
* @return null|string
*/
public function filter($value)
{
if (null === $value || '' === $value) {
$out = null;
} else {
$gmtOffset = 0;
// Reverse WordPress GMT offset when filtering date input
if (function_exists('get_option')) {
$timezoneString = get_option('timezone_string');
$isoValue = date('Y-m-d H:i:s', strtotime($value));
if ($timezoneString) {
$gmtOffset = timezone_offset_get(new DateTimeZone($timezoneString), date_create($isoValue));
}
}
$out = date('Y-m-d H:i:s', strtotime($value) + $gmtOffset * -1);
}
return $out;
}
示例15: timezone_offset
/**
* Utility method that returns time string offset by timezone
* @since 1.0.0
* @param string $tzstring Time string
* @return string Offset time string
*/
public function timezone_offset($tzstring)
{
$tz_offset = 0;
if (!empty($tzstring) && is_string($tzstring)) {
if ('UTC' === substr($tzstring, 0, 3)) {
$tzstring = str_replace(array(':15', ':30', ':45'), array('.25', '.5', '.75'), $tzstring);
return intval(floatval(substr($tzstring, 3)) * HOUR_IN_SECONDS);
}
try {
$date_time_zone_selected = new DateTimeZone($tzstring);
$tz_offset = timezone_offset_get($date_time_zone_selected, date_create());
} catch (Exception $e) {
if (defined('WP_DEBUG') && WP_DEBUG) {
error_log('CMB2_Sanitize:::text_datetime_timestamp_timezone, ' . __LINE__ . ': ' . print_r($e->getMessage(), true));
}
}
}
return $tz_offset;
}