コード例 #1
1
ファイル: TimeZoneTest.php プロジェクト: youprofit/Zurmo
 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);
 }
コード例 #2
0
 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']);
     }
 }
コード例 #3
0
 /**
  * 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;
 }
コード例 #4
0
ファイル: Anemometer.php プロジェクト: asura0129/Anemometer
 /**
  * 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
0
ファイル: AriiDate.php プロジェクト: AxelANGENAULT/CoreBundle
 private function getOffset($tz)
 {
     if ($tz == '') {
         return 0;
     }
     # Heure GMT
     return timezone_offset_get(new \DateTimeZone($tz), new \DateTime());
 }
コード例 #6
0
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
0
 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' => '*****@*****.**', '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 = '******';
     $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
0
ファイル: CMB2_Utils.php プロジェクト: kps3/wordpress-base
 /**
  * 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;
 }
コード例 #9
0
ファイル: AriiDate.php プロジェクト: AriiPortal/Arii
 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;
 }
コード例 #10
0
	/**
	 * 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
0
 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");
 }
コード例 #12
0
ファイル: CMB2_Utils.php プロジェクト: markbiek/Silencio
 /**
  * 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;
 }
コード例 #13
0
ファイル: FlotRenderer.php プロジェクト: librette/flot
 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
0
ファイル: IsoTimestamp.php プロジェクト: deltasystems/dewdrop
 /**
  * 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
0
ファイル: CMB2_Utils.php プロジェクト: jrajalu/myxon
 /**
  * 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;
 }
コード例 #16
0
ファイル: ftpclient.php プロジェクト: revsm/procureor
 function __construct($connect_data)
 {
     $this->tz_offset = timezone_offset_get(timezone_open(date_default_timezone_get()), new DateTime());
     $this->FTP_STATE_NAME = array(0 => 'DISCONNECTED', 1 => 'CONNECTED', 2 => 'LOGGED IN', 3 => 'TARGETED');
     $this->FTP_STATUS_NAME = array(-1 => 'ERROR', 0 => 'READY', 1 => 'READING', 2 => 'NOT READ');
     $this->months = array("Jan" => 1, "Feb" => 2, "Mar" => 3, "Apr" => 4, "May" => 5, "Jun" => 6, "Jul" => 7, "Aug" => 8, "Sep" => 9, "Oct" => 10, "Nov" => 11, "Dec" => 12);
     $this->user = $connect_data['username'];
     $this->pass = $connect_data['password'];
     $this->listing_cache = array();
     if (isset($connect_data['port'])) {
         $this->port = $connect_data['port'];
     } else {
         $this->port = 21;
     }
     $this->host = $connect_data['host'];
     if (isset($connect_data['path'])) {
         $this->cur_path = $connect_data['path'];
     } else {
         $this->cur_path = '';
     }
 }
コード例 #17
0
/**
 * A method to re-initialize connections to the CMSMS configured database.
 * This method should be used by any UDT's or other plugins that use any other method
 * than the standard CMSMS supplied database object to connect to a database.
 *
 */
function &adodb_connect()
{
    $gCms = cmsms();
    $config = $gCms->GetConfig();
    $str = 'pear:date:extend';
    $dbinstance = ADONewConnection($config['dbms'], $str);
    $dbinstance->raiseErrorFn = "adodb_error";
    $conn_func = isset($config['persistent_db_conn']) && $config['persistent_db_conn'] == true ? 'PConnect' : 'Connect';
    if (!empty($config['db_port'])) {
        $dbinstance->port = $config['db_port'];
    }
    $connect_result = $dbinstance->{$conn_func}($config['db_hostname'], $config['db_username'], $config['db_password'], $config['db_name']);
    if (FALSE == $connect_result) {
        $str = "Attempt to connect to database {$config['db_name']} on {$config['db_username']}@{$config['db_hostname']} failed";
        trigger_error($str, E_USER_ERROR);
        die($str);
    }
    $dbinstance->raiseErrorFn = null;
    $dbinstance->SetFetchMode(ADODB_FETCH_ASSOC);
    if ($config['debug'] == true) {
        $dbinstance->debug = true;
    }
    $p1 = array();
    if ($config['set_names'] == true) {
        $p1[] = "NAMES 'utf8'";
    }
    if ($config['set_db_timezone'] == true) {
        $dt = new DateTime();
        $dtz = new DateTimeZone($config['timezone']);
        $offset = timezone_offset_get($dtz, $dt);
        $symbol = $offset < 0 ? '-' : '+';
        $hrs = abs((int) ($offset / 3600));
        $mins = abs((int) ($offset % 3600));
        $p1[] = sprintf("time_zone = '%s%d:%02d'", $symbol, $hrs, $mins);
    }
    $dbinstance->Execute('SET ' . implode(',', $p1));
    return $dbinstance;
}
コード例 #18
0
ファイル: functions.php プロジェクト: rapla/rapla.freiraum-p
/**
 * Diese Funktion transformiert die Daten, die von der Funktion getAppointmentByResource erstellt wurden,
 * in eine Datenstruktur, die auf der Oberfläche geparsed und angezeigt werden kann.
 */
function transformAppointmentsToHtml($result, $exclude_id, $class, $tag_ende, $tag_offset)
{
    $data = "";
    foreach ($result as $values) {
        $appointment_id = $values["ID"];
        $output = getEventOfAppointment($appointment_id);
        $output .= getRessourcesOfAppointment($appointment_id, $exclude_id);
        $duration = ($values["end_ts"] - $values["begin_ts"]) / 3600;
        //Achtung: begin_ts ist der timestamp des ersten TERMINS! Wir erhalten also in der Differenz mit dem Anfragedatum mehrere Tage Unterschied
        //AUSSERDEM: Zeitzonen-Problem!!!!
        //Erster Schritt: Berechne die Anzahl der Tage die zwischen dem ersten Serientermin und heute liegt:
        $anzahlTage = floor(($tag_ende - $values["begin_ts"]) / SECS_PER_DAY);
        //Zweiter Schritt: Prüfe die Gleichheit der Zeitzonen!
        $objDateTimeZone = timezone_open(date_default_timezone_get());
        $date = date("Y-m-d h:i:s", $values["begin_ts"]);
        $timezoneDiffOriginal = $strZeitzoneUnterschiedZuGMT = timezone_offset_get($objDateTimeZone, date_create($date, $objDateTimeZone));
        $timezoneDiffCurrent = $strZeitzoneUnterschiedZuGMT = timezone_offset_get($objDateTimeZone, date_create("now", $objDateTimeZone));
        //echo "begin_ts:".$values["begin_ts"]."anzahlTage:".$anzahlTage."tag_offset:".$tag_offset."tag_ende:".$tag_ende;
        $start = ($values["begin_ts"] + $anzahlTage * SECS_PER_DAY - $tag_offset) / 3600 + ($timezoneDiffOriginal - $timezoneDiffCurrent) / 3600;
        $data .= "<li class='" . $class . "' data-start='" . $start . "' data-duration='" . $duration . "'><ul class='ttEventDetails'>" . $output . "</ul></li>";
    }
    return $data;
}
コード例 #19
0
ファイル: Date.php プロジェクト: ThibautLeger/123-mini
 /**
  * returns a string from array returned by Date::timeAgo()
  * @param $time unix epoch
  * @param $from from unix epoch
  * @param $format array of periods to show
  */
 public static function formatTimeAgo($from, $to, $format = array('year', 'month', 'day', 'hour', 'minute', 'second'))
 {
     // have to calculate the offset
     $default_timezone = timezone_open(date_default_timezone_get());
     $from_datetime = new DateTime(date('Y-m-d H:i:s', $from));
     // add the offset
     $from += timezone_offset_get($default_timezone, $from_datetime);
     $timeago = Date::timeAgo($from, $to);
     $t = array();
     foreach ($format as $period) {
         if (isset($timeago[$period])) {
             $time = $timeago[$period];
             if ($time != 1) {
                 $period .= 's';
             }
             $t[] = "{$time} [{$period}]";
         }
     }
     $t = implode(" ", $t);
     if (!trim($t)) {
         return (string) '0';
     }
     return $t;
 }
コード例 #20
0
 /**
  * Get weekly shedule for a particular day
  *
  * @param $timestamp
  * @return array
  */
 function getSchedule($timestamp)
 {
     if (!$this->zermelo->token) {
         return 403;
     }
     $subjects = (array) json_decode(file_get_contents('lib/Assets/subjects.json'));
     $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);
     $result = array('week_timestamp' => $weekstart, 'days' => array());
     $curday = $weekstart;
     while ($curday <= $weekend) {
         $curwd = (int) date('w', $curday);
         $result['days'][$curwd] = array('day_title' => $this->dutchDayName($curday), 'day_ofweek' => (int) date('w', $curday), 'items' => array());
         $start = $curday;
         $end = $curday + 86399;
         $data = $this->zermelo->getStudentGrid($start, $end);
         foreach ($data as $item) {
             $item = (object) $item;
             $start = (int) $item->start;
             $vakname = isset($subjects[$item->subjects[0]]) ? $subjects[$item->subjects[0]] : $item->subjects[0];
             $teacher = $item->teachers[0];
             $cancelled = $item->cancelled;
             $moved = $item->moved;
             $teacher = preg_replace('/^.*-\\s*/', '', $teacher);
             if (empty($item->locations)) {
                 $item->locations = array('onbekend');
             }
             $result['days'][$curwd]['items'][] = array('title' => $vakname, 'subtitle' => 'Lokaal ' . $item->locations[0], 'teacher' => strtoupper($teacher), 'cancelled' => $cancelled, 'moved' => $moved, 'start' => $start, 'start_str' => date('H:i', $start + $tz_offset));
         }
         $curday += 86400;
     }
     return $result;
 }
コード例 #21
0
ファイル: Preferences.php プロジェクト: nahoj/mediawiki_ynh
	/**
	 * @param $context IContextSource
	 * @return array
	 */
	static function getTimezoneOptions( IContextSource $context ) {
		$opt = array();

		global $wgLocalTZoffset;
		$timestamp = MWTimestamp::getLocalInstance();
		// Check that $wgLocalTZoffset is the same as the local time zone offset
		if ( $wgLocalTZoffset == $timestamp->format( 'Z' ) / 60 ) {
			$server_tz_msg = $context->msg( 'timezoneuseserverdefault', $timestamp->getTimezone()->getName() )->text();
		} else {
			$tzstring = sprintf( '%+03d:%02d', floor( $wgLocalTZoffset / 60 ), abs( $wgLocalTZoffset ) % 60 );
			$server_tz_msg = $context->msg( 'timezoneuseserverdefault', $tzstring )->text();
		}
		$opt[$server_tz_msg] = "System|$wgLocalTZoffset";
		$opt[$context->msg( 'timezoneuseoffset' )->text()] = 'other';
		$opt[$context->msg( 'guesstimezone' )->text()] = 'guess';

		if ( function_exists( 'timezone_identifiers_list' ) ) {
			# Read timezone list
			$tzs = timezone_identifiers_list();
			sort( $tzs );

			$tzRegions = array();
			$tzRegions['Africa'] = $context->msg( 'timezoneregion-africa' )->text();
			$tzRegions['America'] = $context->msg( 'timezoneregion-america' )->text();
			$tzRegions['Antarctica'] = $context->msg( 'timezoneregion-antarctica' )->text();
			$tzRegions['Arctic'] = $context->msg( 'timezoneregion-arctic' )->text();
			$tzRegions['Asia'] = $context->msg( 'timezoneregion-asia' )->text();
			$tzRegions['Atlantic'] = $context->msg( 'timezoneregion-atlantic' )->text();
			$tzRegions['Australia'] = $context->msg( 'timezoneregion-australia' )->text();
			$tzRegions['Europe'] = $context->msg( 'timezoneregion-europe' )->text();
			$tzRegions['Indian'] = $context->msg( 'timezoneregion-indian' )->text();
			$tzRegions['Pacific'] = $context->msg( 'timezoneregion-pacific' )->text();
			asort( $tzRegions );

			$prefill = array_fill_keys( array_values( $tzRegions ), array() );
			$opt = array_merge( $opt, $prefill );

			$now = date_create( 'now' );

			foreach ( $tzs as $tz ) {
				$z = explode( '/', $tz, 2 );

				# timezone_identifiers_list() returns a number of
				# backwards-compatibility entries. This filters them out of the
				# list presented to the user.
				if ( count( $z ) != 2 || !array_key_exists( $z[0], $tzRegions ) ) {
					continue;
				}

				# Localize region
				$z[0] = $tzRegions[$z[0]];

				$minDiff = floor( timezone_offset_get( timezone_open( $tz ), $now ) / 60 );

				$display = str_replace( '_', ' ', $z[0] . '/' . $z[1] );
				$value = "ZoneInfo|$minDiff|$tz";

				$opt[$z[0]][$display] = $value;
			}
		}
		return $opt;
	}
コード例 #22
0
ファイル: ticket.php プロジェクト: kevinwojo/hubzero-cms
        // ACL can update ticket (admin)
        ?>
						
				<?php 
        if ($this->row->access('update', 'tickets') > 0) {
            ?>
						</div>
					</div>

					<label for="field-target_date">
						<?php 
            echo Lang::txt('COM_SUPPORT_COMMENT_TARGET_DATE');
            ?>
:
						<input type="text" name="ticket[target_date]" class="datetime-field" id="field-target_date" data-timezone="<?php 
            echo timezone_offset_get(new DateTimeZone(Config::get('offset')), Date::getRoot()) / 60;
            ?>
" placeholder="YYYY-MM-DD hh:mm:ss" value="<?php 
            echo $this->row->get('target_date') && $this->row->get('target_date') != '0000-00-00 00:00:00' ? $this->escape(Date::of($this->row->get('target_date'))->toLocal('Y-m-d H:i:s')) : '';
            ?>
" />
					</label>

					<?php 
            if (isset($this->lists['categories']) && $this->lists['categories']) {
                ?>
					<label for="ticket-field-category">
						<?php 
                echo Lang::txt('COM_SUPPORT_COMMENT_CATEGORY');
                ?>
:
コード例 #23
0
ファイル: functions.php プロジェクト: hpilevar/WordPress
/**
 * gmt_offset modification for smart timezone handling.
 *
 * Overrides the gmt_offset option if we have a timezone_string available.
 *
 * @since 2.8.0
 *
 * @return float|false Timezone GMT offset, false otherwise.
 */
function wp_timezone_override_offset()
{
    if (!($timezone_string = get_option('timezone_string'))) {
        return false;
    }
    $timezone_object = timezone_open($timezone_string);
    $datetime_object = date_create();
    if (false === $timezone_object || false === $datetime_object) {
        return false;
    }
    return round(timezone_offset_get($timezone_object, $datetime_object) / HOUR_IN_SECONDS, 2);
}
コード例 #24
0
    // 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 
    $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.');
        }
コード例 #25
0
ファイル: User.php プロジェクト: alexanderkuz/test-yii2
 public static function calcOffsetTimeZone($timezone)
 {
     $offset = timezone_offset_get(new DateTimeZone($timezone), new DateTime());
     $absoffset = abs($offset);
     $hour = floor($absoffset / 3600);
     return sprintf("%s%02d:%02d", $offset >= 0 ? '+' : '-', $hour, ($absoffset - $hour * 3600) / 60);
 }
コード例 #26
0
ファイル: class.Config.php プロジェクト: prabhatse/olx_hack
 /**
  * Returns the GMT offset in hours based on the application's defined timezone.
  *
  * If $time is given, gives the offset for that time; otherwise uses the current time.
  *
  * @param int $time The time to base it on, as anything strtotime() takes; leave blank for current time.
  * @return int The GMT offset in hours.
  */
 public function getGMTOffset($time = 0)
 {
     $time = $time ? $time : 'now';
     $tz = $this->getValue('timezone') == null ? date('e') : $this->getValue('timezone');
     // this may be currently required for some setups to avoid fatal php timezone complaints when
     // exec'ing off the streaming child processes.
     // date_default_timezone_set($tz);
     return timezone_offset_get(new DateTimeZone($tz), new DateTime($time)) / 3600;
 }
        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);
$datetime = new DateTime("2009-01-31 15:14:10");
foreach ($inputs as $variation => $object) {
    echo "\n-- {$variation} --\n";
    try {
        var_dump(timezone_offset_get($object, $datetime));
    } catch (Error $ex) {
        echo $ex->getMessage() . "\n";
    }
}
// closing the resource
fclose($file_handle);
?>
===DONE===
コード例 #28
0
ファイル: functions.php プロジェクト: Ogwang/sainp
/**
 * gmt_offset modification for smart timezone handling
 *
 * Overrides the gmt_offset option if we have a timezone_string available
 *
 * @since 2.8.0
 *
 * @return float|bool
 */
function wp_timezone_override_offset()
{
    if (!wp_timezone_supported()) {
        return false;
    }
    if (!($timezone_string = get_option('timezone_string'))) {
        return false;
    }
    $timezone_object = timezone_open($timezone_string);
    $datetime_object = date_create();
    if (false === $timezone_object || false === $datetime_object) {
        return false;
    }
    return round(timezone_offset_get($timezone_object, $datetime_object) / 3600, 2);
}
コード例 #29
0
 /**
  * @param User $user
  * @param IContextSource $context
  * @param array $defaultPreferences
  * @return void
  */
 static function datetimePreferences($user, IContextSource $context, &$defaultPreferences)
 {
     # # Date and time #####################################
     $dateOptions = self::getDateOptions($context);
     if ($dateOptions) {
         $defaultPreferences['date'] = array('type' => 'radio', 'options' => $dateOptions, 'label' => '&#160;', 'section' => 'rendering/dateformat');
     }
     // Info
     $now = wfTimestampNow();
     $lang = $context->getLanguage();
     $nowlocal = Xml::element('span', array('id' => 'wpLocalTime'), $lang->userTime($now, $user));
     $nowserver = $lang->userTime($now, $user, array('format' => false, 'timecorrection' => false)) . Html::hidden('wpServerTime', (int) substr($now, 8, 2) * 60 + (int) substr($now, 10, 2));
     $defaultPreferences['nowserver'] = array('type' => 'info', 'raw' => 1, 'label-message' => 'servertime', 'default' => $nowserver, 'section' => 'rendering/timeoffset');
     $defaultPreferences['nowlocal'] = array('type' => 'info', 'raw' => 1, 'label-message' => 'localtime', 'default' => $nowlocal, 'section' => 'rendering/timeoffset');
     // Grab existing pref.
     $tzOffset = $user->getOption('timecorrection');
     $tz = explode('|', $tzOffset, 3);
     $tzOptions = self::getTimezoneOptions($context);
     $tzSetting = $tzOffset;
     if (count($tz) > 1 && $tz[0] == 'Offset') {
         $minDiff = $tz[1];
         $tzSetting = sprintf('%+03d:%02d', floor($minDiff / 60), abs($minDiff) % 60);
     } elseif (count($tz) > 1 && $tz[0] == 'ZoneInfo' && !in_array($tzOffset, HTMLFormField::flattenOptions($tzOptions))) {
         # Timezone offset can vary with DST
         $userTZ = timezone_open($tz[2]);
         if ($userTZ !== false) {
             $minDiff = floor(timezone_offset_get($userTZ, date_create('now')) / 60);
             $tzSetting = "ZoneInfo|{$minDiff}|{$tz[2]}";
         }
     }
     $defaultPreferences['timecorrection'] = array('class' => 'HTMLSelectOrOtherField', 'label-message' => 'timezonelegend', 'options' => $tzOptions, 'default' => $tzSetting, 'size' => 20, 'section' => 'rendering/timeoffset');
 }
コード例 #30
0
 /**
  * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
  * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
  * the site is used.
  *
  * This is used typically when using a Unix timestamp any core WP functions that expect their specially
  * computed timestamp (i.e. date_i18n() )
  *
  * @param int      $unix_timestamp   if 0, then time() will be used.
  * @param string $timezone_string timezone_string. If empty, then the current set timezone for the site will
  *                                		        be used.
  *
  * @return int      $unix_timestamp with the offset applied for the given timezone.
  */
 public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '')
 {
     $unix_timestamp = $unix_timestamp === 0 ? time() : (int) $unix_timestamp;
     $timezone_string = self::get_valid_timezone_string($timezone_string);
     $TimeZone = new DateTimeZone($timezone_string);
     $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone);
     $offset = timezone_offset_get($TimeZone, $DateTime);
     return (int) $DateTime->format('U') + (int) $offset;
 }