public function get_current_date_start_time($country_code = 'BD') { $time_zone_array = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, $country_code); $dateTimeZone = new DateTimeZone($time_zone_array[0]); $dateTime = new DateTime("now", $dateTimeZone); $unix_current_time = now() + $dateTime->getOffset(); $human_current_time = unix_to_human($unix_current_time); $human_current_time_array = explode(" ", $human_current_time); $human_current_date = $human_current_time_array[0]; $human_current_date_start_time = $human_current_date . ' 00:00 AM'; $unix_current_date_start_time = human_to_unix($human_current_date_start_time); return $unix_current_date_start_time - $dateTime->getOffset(); }
/** * Required plugin startup method */ public function init() { self::$instance = $this; $this->rc = rcube::get_instance(); // set user's timezone try { $this->timezone = new DateTimeZone($this->rc->config->get('timezone', 'GMT')); } catch (Exception $e) { $this->timezone = new DateTimeZone('GMT'); } $now = new DateTime('now', $this->timezone); $this->gmt_offset = $now->getOffset(); $this->dst_active = $now->format('I'); $this->timezone_offset = $this->gmt_offset / 3600 - $this->dst_active; $this->add_texts('localization/', false); // include client scripts and styles if ($this->rc->output) { // add hook to display alarms $this->add_hook('refresh', array($this, 'refresh')); $this->register_action('plugin.alarms', array($this, 'alarms_action')); $this->register_action('plugin.expand_attendee_group', array($this, 'expand_attendee_group')); } // proceed initialization in startup hook $this->add_hook('startup', array($this, 'startup')); }
/** * * Possible bug was also detected: date_sunrise() seems to return date of the previous day: * https://bugs.php.net/bug.php?id=53148 * * To avoid issues, only compare day agnostic formats: $dt->format('Hi') * * @param \DateTime $dateTime * @param $method * * @return \DateTime */ private function getChangeTime(\DateTime $dateTime, $method) { $location = $dateTime->getTimezone()->getLocation(); $horizonShift = new \DateTime('now', $dateTime->getTimezone()); $horizonShift->setTimestamp($method($dateTime->getTimestamp(), SUNFUNCS_RET_TIMESTAMP, $location['latitude'], $location['longitude'], ini_get("date.sunrise_zenith"), $dateTime->getOffset() / 3600)); return $horizonShift; }
public function GET() { $policy = new Policy_LoggedIn($this->app); $app = Config::get('app'); $userid = $policy->getData(); $request = $this->app->request(); if (!$userid) { throw new Exception_Api("Unable to authenticate."); } $days_back = trim($request->get('days_back')); if (!is_numeric($days_back) && $days_back != 'all' && $days_back != 'ytd') { throw new Exception_Api('Missing or invalid days_back field.'); } $mapper = new Mapper_Settings(); $mapper->updateSettingForUserid($userid, 'default_view', $days_back); $settings = $mapper->getFilteredSettingsByUserid($userid); $serverDateTimeZone = new DateTimeZone($app->default_timezone); $userDateTimeZone = new DateTimeZone($settings['timezone']); $serverDateTime = new DateTime("now", $serverDateTimeZone); $userDateTime = new DateTime("now", $userDateTimeZone); $tzDiff = $userDateTime->getOffset() - $serverDateTime->getOffset(); $tzDiff = $tzDiff / (60 * 60); $weight_mapper = new Mapper_Weight(); $weights = $weight_mapper->getWeightsForUser($userid, $days_back); $formatted_weights = array(); foreach ($weights as $weight) { $formatted_weights[] = array('date' => $weight['create_time'], 'weight' => $weight['weight'], 'comment' => htmlentities($weight['comment'])); } return array('data' => $formatted_weights, 'units' => $app->weight_units, 'tz_offset' => $tzDiff); }
public function connecting() { $now = new DateTime(); $mins = $now->getOffset() / 60; $sgn = $mins < 0 ? -1 : 1; $mins = abs($mins); $hrs = floor($mins / 60); $mins -= $hrs * 60; $offset = sprintf('%+d:%02d', $hrs * $sgn, $mins); // @formatter:off $this->dsn = $this->parametro['MotorBD'] . ":host=" . $this->parametro['HostBD'] . ";dbname=" . $this->parametro['NameBD']; // @formatter:on if (!self::$PDOInstance) { try { self::$PDOInstance = new PDO($this->dsn, $this->parametro['UserBD'], $this->parametro['PassBD']); // self::$PDOInstance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); self::$PDOInstance->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES utf8"); self::$PDOInstance->setAttribute(PDO::ATTR_PERSISTENT, false); self::$PDOInstance->exec("SET time_zone = '{$offset}';"); } catch (PDOException $e) { header('HTTP/1.0 500 Internal Server Error'); // $this->logs->error("Error al conectar: ", $e->getMessage()); echo "Error al conectar: " . $e->getMessage() . "<br/>"; exit; } } }
function timezones() { $list = DateTimeZone::listIdentifiers(); $data = array(); foreach ($list as $id => $zone) { $now = new DateTime(null, new DateTimeZone($zone)); $offset = $now->getOffset(); $offset_round = round(abs($offset / 3600), 2); $minutes = fmod($offset_round, 1); if ($minutes == 0) { $offset_label = $offset_round . ' '; } elseif ($minutes == 0.5) { $offset_label = (int) $offset_round . '.30'; } elseif ($minutes == 0.75) { $offset_label = (int) $offset_round . '.45'; } $sign = $offset > 0 ? '+' : '-'; if ($offset == 0) { $sign = ' '; $offset = ''; } $label = 'GMT' . $sign . $offset_label . ' ' . $zone; $data[$offset][$zone] = array('offset' => $offset, 'label' => $label, 'timezone_id' => $zone); } ksort($data); $timezones = array(); foreach ($data as $offsets) { ksort($offsets); foreach ($offsets as $zone) { $timezones[] = $zone; } } return $timezones; }
private function _setDatabaseOptions() { if (is_object(Config::getInstance()->getValue('database'))) { if (Config::getInstance()->getValue('database')->hasValue('charset')) { $lCharset = Config::getInstance()->getValue('database')->getValue('charset'); } else { trigger_error('Warning undefined charset database. By default charset is set to \'utf8\' '); $lCharset = 'utf8'; } if (Config::getInstance()->getValue('database')->hasValue('timezone')) { $lTimezone = Config::getInstance()->getValue('database')->getValue('timezone'); } else { trigger_error('Warning undefined timezone database. By default charset is set to \'utf8\' '); $lTimezone = 'UTC'; } } else { trigger_error('Warning undefined database options connections'); $lCharset = 'utf8'; $lTimezone = 'UTC'; } $lDate = new \DateTime('now', new \DateTimeZone($lTimezone)); $lTotalOffsetSeconds = $lDate->getOffset(); $lOffsetOperator = $lTotalOffsetSeconds >= 0 ? '+' : '-'; $lOffsetHours = floor(abs($lTotalOffsetSeconds) / 3600); $lOffsetMinutes = floor(abs($lTotalOffsetSeconds) % 3600 / 60); $lOffset = $lOffsetOperator . $lOffsetHours . ':' . $lOffsetMinutes; $this->mDbHandle->exec("SET NAMES {$lCharset};"); $this->mDbHandle->exec("SET time_zone = '{$lOffset}';"); }
/** get time zone offset * * @param string $zone */ function getZoneOffset($zone) { $a = new DateTimeZone($zone); $b = new DateTime("now", $a); $offset = $b->getOffset() / 3600; return $offset; }
/** * Establishing database connection * @return database connection handler */ function connect() { include_once dirname(__FILE__) . '/Config.php'; //Setting timezone to PHP date_default_timezone_set(TIMEZONE); // Connecting to mysql database $this->conn = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME); //Setting time zone to MySQL $now = new DateTime(); $mins = $now->getOffset() / 60; $sgn = $mins < 0 ? -1 : 1; $mins = abs($mins); $hrs = floor($mins / 60); $mins -= $hrs * 60; $offset = sprintf('%+d:%02d', $hrs * $sgn, $mins); $stmt = $this->conn->prepare("SET time_zone='{$offset}'"); $stmt->execute(); $stmt->close(); //echo "offset=".$offset."\n"; // Check for database connection error if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // returing connection resource return $this->conn; }
public function __construct() { $timeNow = time(); //test $checkOffset = new \DateTime(date('d.m.Y', $timeNow), new \DateTimeZone(self::$tz)); $calcSumWin = $checkOffset->getOffset(); $this->nowTime = strtotime(date('d.m.Y H:i', $timeNow)) + $calcSumWin; if (\OC::$server->getSession()->get('public_link_token')) { $linkItem = \OCP\Share::getShareByToken(\OC::$server->getSession()->get('public_link_token', false)); if (is_array($linkItem) && isset($linkItem['uid_owner'])) { if ($linkItem['item_type'] === App::SHARECALENDAR) { $sPrefix = App::SHARECALENDARPREFIX; } if ($linkItem['item_type'] === App::SHAREEVENT) { $sPrefix = App::SHAREEVENTPREFIX; } if ($linkItem['item_type'] === App::SHARETODO) { $sPrefix = App::SHARETODOPREFIX; } $itemSource = App::validateItemSource($linkItem['item_source'], $sPrefix); $rootLinkItem = Calendar::find($itemSource); $this->aCalendars[] = $rootLinkItem; } } else { if (\OCP\User::isLoggedIn()) { $this->aCalendars = Calendar::allCalendars(\OCP\User::getUser()); $this->checkAlarm(); } } }
static function UtcTimestamp() { //Timestamp as UTC $config = JFactory::getConfig(); $tz = new DateTime('now', new DateTimeZone($config->get('offset'))); return time() - $tz->getOffset(); }
/** * Required plugin startup method */ public function init() { self::$instance = $this; $this->rc = rcube::get_instance(); // set user's timezone try { $this->timezone = new DateTimeZone($this->rc->config->get('timezone', 'UTC')); } catch (Exception $e) { $this->timezone = new DateTimeZone('UTC'); } $now = new DateTime('now', $this->timezone); $this->gmt_offset = $now->getOffset(); $this->dst_active = $now->format('I'); $this->timezone_offset = $this->gmt_offset / 3600 - $this->dst_active; $this->add_texts('localization/', false); // include client scripts and styles if ($this->rc->output) { if ($this->rc->output->type == 'html') { $this->rc->output->set_env('libcal_settings', $this->load_settings()); $this->rc->output->add_header(html::tag('script', array('type' => 'text/javascript', 'src' => 'plugins/libgpl/libcalendaring/libcalendaring.js'))); $this->include_stylesheet($this->local_skin_path() . '/libcal.css'); } // add hook to display alarms $this->add_hook('refresh', array($this, 'refresh')); $this->register_action('plugin.alarms', array($this, 'alarms_action')); } }
function ShowInformationPage() { global $LNG, $CONF, $USER; if (file_exists(ini_get('error_log'))) { $Lines = count(file(ini_get('error_log'))); } else { $Lines = 0; } try { $dateTimeZoneServer = new DateTimeZone(Config::get('timezone')); } catch (Exception $e) { $dateTimeZoneServer = new DateTimeZone(date_default_timezone_get()); } try { $dateTimeZoneUser = new DateTimeZone($USER['timezone']); } catch (Exception $e) { $dateTimeZoneUser = new DateTimeZone(date_default_timezone_get()); } try { $dateTimeZonePHP = new DateTimeZone(ini_get('date.timezone')); } catch (Exception $e) { $dateTimeZonePHP = new DateTimeZone(date_default_timezone_get()); } $dateTimeServer = new DateTime("now", $dateTimeZoneServer); $dateTimeUser = new DateTime("now", $dateTimeZoneUser); $dateTimePHP = new DateTime("now", $dateTimeZonePHP); $template = new template(); $template->assign_vars(array('info_information' => sprintf($LNG['info_information'], 'http://tracker.2moons.cc/'), 'info' => $_SERVER['SERVER_SOFTWARE'], 'vPHP' => PHP_VERSION, 'vAPI' => PHP_SAPI, 'vGame' => Config::get('VERSION'), 'vMySQLc' => $GLOBALS['DATABASE']->getVersion(), 'vMySQLs' => $GLOBALS['DATABASE']->getServerVersion(), 'root' => $_SERVER['SERVER_NAME'], 'gameroot' => $_SERVER['SERVER_NAME'] . str_replace('/admin.php', '', $_SERVER['PHP_SELF']), 'json' => function_exists('json_encode') ? 'Ja' : 'Nein', 'bcmath' => extension_loaded('bcmath') ? 'Ja' : 'Nein', 'curl' => extension_loaded('curl') ? 'Ja' : 'Nein', 'browser' => $_SERVER['HTTP_USER_AGENT'], 'safemode' => ini_get('safe_mode') ? 'Ja' : 'Nein', 'memory' => ini_get('memory_limit'), 'suhosin' => ini_get('suhosin.request.max_value_length') ? 'Ja' : 'Nein', 'log_errors' => ini_get('log_errors') ? 'Aktiv' : 'Inaktiv', 'errorlog' => ini_get('error_log'), 'errorloglines' => $Lines, 'php_tz' => $dateTimePHP->getOffset() / 3600, 'conf_tz' => $dateTimeServer->getOffset() / 3600, 'user_tz' => $dateTimeUser->getOffset() / 3600)); $template->show('ShowInformationPage.tpl'); }
function connect_pdo($config) { // computing timezone difference with gmt: // http://www.sitepoint.com/synchronize-php-mysql-timezone-configuration/ $now = new DateTime(); $mins = $now->getOffset() / 60; $sgn = $mins < 0 ? -1 : 1; $mins = abs($mins); $hrs = floor($mins / 60); $mins -= $hrs * 60; $offset = sprintf('%+d:%02d', $hrs * $sgn, $mins); try { $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; $pdo_options[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES utf8"; $connexionString = "mysql:host=" . $config->db->mysql->host . ";dbname=" . $config->db->mysql->database; if ($config->db->mysql->logged) { $db = new LoggedPDO($connexionString, $config->db->mysql->user, $config->db->mysql->password, $pdo_options); } else { $db = new PDO($connexionString, $config->db->mysql->user, $config->db->mysql->password, $pdo_options); } $db->exec("SET time_zone='" . $offset . "';"); } catch (Exception $e) { die("Erreur : " . $e->getMessage()); } return $db; }
public static function getAllTimeZones() { $file = dirname(__FILE__) . "/data/timezones.php"; if (file_exists($file)) { return include $file; } $data = DateTimeZone::listIdentifiers(); $time_zones = array(); foreach ($data as $time_zone_id) { $t = explode('/', $time_zone_id, 2); $date_time = new DateTime('now'); $tz = new DateTimeZone($time_zone_id); $date_time->setTimezone($tz); $offset = (double) $date_time->getOffset() / 3600; $group = count($tz->getTransitions(strtotime('-1 year'), time())); if (isset($t[1])) { $time_zones[$offset][$group][$t[0]][] = $t[1]; } else { $time_zones[$offset][$group][''][] = $t[0]; } } ksort($time_zones); $result = array(); foreach ($time_zones as $offset => $group_offset_zones) { foreach ($group_offset_zones as $group => $offset_zones) { if ($offset >= 10) { $str_offset = '+' . $offset; } elseif ($offset >= 0 && $offset < 10) { $str_offset = '+0' . $offset; } elseif ($offset < 0 && $offset > -10) { $str_offset = '−0' . abs($offset); } elseif ($offset <= -10) { $str_offset = '−' . abs($offset); } foreach ($offset_zones as $continent => $zones) { if (count($zones) <= 5) { $result[($continent ? $continent . "/" : '') . $zones[0]] = array($str_offset, $zones); } else { $i = 0; $n = count($zones); while ($i < $n) { $tmp = array(); for ($j = 0; $j < 5 && $i + $j < $n; $j++) { $z = $zones[$i + $j]; if (($k = strpos($z, '/')) !== false) { $z = substr($z, $k + 1); } $tmp[] = $z; } $result[$continent . "/" . $zones[$i]] = array($str_offset, $tmp); $i += 5; } } } } } waUtils::varExportToFile($result, dirname(__FILE__) . "/data/timezones.php"); return $result; }
/** * get gmt offset in minutes * @param varchar $timezone php compatible timezone * @return int */ public static function getGmtOffset($timezone) { $now = new \DateTime(); if (System::isValidTimezone($timezone)) { $now->setTimezone(new \DateTimeZone($timezone)); } return $now->getOffset() / 60; }
/** * Transforms a datetime string into a DateTime object in the UTC (GMT) timezone * (Assumes that $datetime_string is currently in the timezone set in the Magento config) * @param $datetime * @return DateTime */ public function convertToGmt($datetime) { $timezoneStore = new DateTimeZone(Mage::getStoreConfig('general/locale/timezone')); $datetimeStore = new DateTime($datetime, $timezoneStore); // offset in seconds, including daylight savings time $datetimeOffset = $datetimeStore->getOffset(); $datetimeStore->modify('-' . $datetimeOffset . ' seconds'); return $datetimeStore; }
/** * @param \DateTime $date * @return \DateTime */ private function convertToUtc(\DateTime $date) { if (null === $this->utc) { $this->utc = new \DateTimeZone('UTC'); } if ($date->getOffset() !== 0) { $date->setTimezone($this->utc); } return $date; }
/** * Get the absolute (UTC) offset of a timezone. * * @param string $timezone Timezone identifier, e.g. Asia/Seoul * @param int $timestamp Unix timestamp (optional, default is now) * @return int */ public static function getTimezoneOffset($timezone, $timestamp = null) { if (!isset(self::$_timezones[$timezone])) { self::$_timezones[$timezone] = new \DateTimeZone($timezone); } $datetime = new \DateTime(); $datetime->setTimestamp($timestamp ?: time()); $datetime->setTimezone(self::$_timezones[$timezone]); return $datetime->getOffset(); }
/** * Get Time Zone Offset by Time Zone ID * * @param string $timeZoneId Time Zone ID * * @return int Return the Time Zone Offset; false otherwise */ public function getTimeZoneOffsetByTimeZoneId($timeZoneId) { try { $dt = new \DateTime(null, new \DateTimeZone($timeZoneId)); //Return return $dt->getOffset(); } catch (\Exception $e) { throw $e; } }
public static function getTimezoneOffset() { $now = new \DateTime(); $mins = $now->getOffset() / 60; $sgn = $mins < 0 ? -1 : 1; $mins = abs($mins); $hrs = floor($mins / 60); $mins -= $hrs * 60; return sprintf("%+d:%02d", $hrs * $sgn, $mins); }
public function set_timezone(){ $now = new \DateTime(); $mins = $now->getOffset() / 60; $sign = ($mins < 0 ? -1 : 1); $mins = abs($mins); $hrs = floor($mins / 60); $mins -= $hrs * 60; $offset = sprintf('%+d:%02d', $hrs*$sign, $mins); $params = array($offset); $this->query('SET time_zone=?', $params); }
/** * Get timezone offset by string or object * * @param string|DateTimeZone $timeZoneString String time zone to override user timezone * @return int */ public static function getTimeZoneOffset($timeZoneString) { $dt = new DateTime('@' . XenForo_Application::$time); if ($timeZoneString instanceof DateTimeZone) { $timeZone = $timeZoneString; } else { $timeZone = new DateTimeZone($timeZoneString); } $dt->setTimezone($timeZone); return $dt->getOffset(); }
/** * Get all of the time zones with the offsets sorted by their offset * * @return array */ public static function getAll() { $timeZones = []; $timeZoneIdentifiers = \DateTimeZone::listIdentifiers(); foreach ($timeZoneIdentifiers as $timeZone) { $date = new \DateTime('now', new \DateTimeZone($timeZone)); $offset = $date->getOffset() / 60 / 60; $timeZones[] = ['timezone' => $timeZone, 'name' => "{$timeZone} (UTC " . ($offset > 0 ? '+' : '') . "{$offset})", 'offset' => $offset]; } \yii\helpers\ArrayHelper::multisort($timeZones, 'offset', SORT_DESC, SORT_NUMERIC); return $timeZones; }
/** * Used for GMT offset for a timezone * @param string $timezone: timezone name * @return string GMT offset for the given timezone * @author Laxmi Saini */ function getTimezoneOffset($timezone = null) { if ($timezone != '') { $dateTimeObj = new DateTime(); $date_time_zone = CakeTime::timezone($timezone); $dateTimeObj->setTimeZone($date_time_zone); $offset = $dateTimeObj->getOffset(); return $this->formatGmtOffset($offset); } else { return ""; } }
private function getRelativeTime($timeString) { // ToDo what about relative time? $datetime = new \DateTime($timeString); $time = $datetime->getTimestamp() + $datetime->getOffset(); if (function_exists('\\OCP\\relative_modified_date')) { $time = \OCP\relative_modified_date($time); } else { $time = $this->l10n->l('datetime', $time); } return $time; }
/** * Get the current timezone offset. * * @param boolean $textFormat True to format as text, false otherwise (optional) * @param string $hourSeparator Hour separator (optional) * @param string $timezone Timezone (optional) * @return mixed Default timezone offset */ public static function getTimezoneOffset($textFormat = false, $hourSeparator = ':', $timezone = null) { // Retrieve the current timezone offset $currentTimezone = new DateTimeZone($timezone ? $timezone : self::getTimezone()); $now = new DateTime('now', $currentTimezone); $offset = $now->getOffset(); // Prepare the offset if ($textFormat) { $offset = sprintf("%+03d{$hourSeparator}%02u", $offset / 3600, abs($offset) % 3600 / 60); } return $offset; }
function getDayOfWeek($pTimezone) { $userDateTimeZone = new DateTimeZone($pTimezone); $UserDateTime = new DateTime("now", $userDateTimeZone); $offsetSeconds = $UserDateTime->getOffset(); //echo $offsetSeconds; return gmdate("l", time() + $offsetSeconds); }
/** * Class process method wnich is used to execute this component. */ public function process() { $sCurrentTimeZone = Phpfox::getTimeZone() == '0' ? '' : ' ' . (substr(Phpfox::getTimeZone(), 0, 1) == '-' ? Phpfox::getTimeZone() : '+' . Phpfox::getTimeZone()); if (substr(Phpfox::getTimeZone(), 0, 1) == 'z' && PHPFOX_USE_DATE_TIME) { $aTimeZones = Phpfox::getService('core')->getTimeZones(); if (isset($aTimeZones[Phpfox::getTimeZone()])) { $oDTZ = new DateTime('now', new DateTimeZone($aTimeZones[Phpfox::getTimeZone()])); $sCurrentTimeZone = $oDTZ->getOffset() / 3600; } } $this->template()->assign(array('sCurrentSiteTime' => Phpfox::getTime(Phpfox::getParam('forum.global_forum_timezone'), PHPFOX_TIME), 'sCurrentTimeZone' => $sCurrentTimeZone)); }
private function setTimeZone($timezone) { date_default_timezone_set($timezone); ini_set('date.timezone', $timezone); $now = new DateTime(); $mins = $now->getOffset() / 60; $sgn = $mins < 0 ? -1 : 1; $mins = abs($mins); $hrs = floor($mins / 60); $mins -= $hrs * 60; $offset = sprintf('%+d:%02d', $hrs * $sgn, $mins); $this->conexion->query("SET time_zone = '{$offset}';"); }