Exemplo n.º 1
0
 function &getClientTZ()
 {
     // if SITE_TIME_ZONE is present, use it, otherwise, best guess as to server's local time zone
     if (defined('SITE_TIME_ZONE') && Date_TimeZone::isValidID(SITE_TIME_ZONE)) {
         $client_tz = new Date_TimeZone(SITE_TIME_ZONE);
     } else {
         $client_tz =& Date_TimeZone::getDefault();
     }
     return $client_tz;
 }
Exemplo n.º 2
0
 function NDate($date = null, $now = null)
 {
     $n = func_num_args();
     $p = $n == 3;
     $args = func_get_args();
     $this->tz = Date_TimeZone::getDefault();
     if ($n == 0) {
         return parent::Date();
     }
     $n--;
     $date = $args[$n];
     if (is_array($date)) {
         $this->setDate($date);
     } elseif (is_int($date) || is_string($date) && (string) (int) $date == (string) $date && $date < 9876543210 && $date > 01234567) {
         // Looks like a UNIX timestamp
         parent::Date($date);
     } elseif (is_string($date)) {
         $this->setDate(strtotime($date));
     } else {
         parent::Date($date);
     }
     while ($n > 0) {
         $n--;
         $now = $this->getDate(DATE_FORMAT_UNIXTIME);
         $date = $args[$n];
         switch ($date) {
             case "1st":
             case "first":
                 $this->setDay(1);
                 break;
             case "last":
                 $this->setDay($this->getDaysInMonth());
                 break;
             default:
                 $this->setDate(strtotime($date, $now));
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Converts this date to a new time zone, given a valid time zone ID
  *
  * Converts this date to a new time zone, given a valid time zone ID
  * WARNING: This may not work correctly if your system does not allow
  * putenv() or if localtime() does not work in your environment.  See
  * Date::TimeZone::inDaylightTime() for more information.
  *
  * @access public
  * @param string id a time zone id
  */
 function convertTZbyID($id)
 {
     if (Date_TimeZone::isValidID($id)) {
         $tz = new Date_TimeZone($id);
     } else {
         $tz = Date_TimeZone::getDefault();
     }
     $this->convertTZ($tz);
 }
Exemplo n.º 4
0
 /**
  * sets time zone to the default time zone
  *
  * If PHP version >= 5.1.0, uses the php.ini configuration directive
  * 'date.timezone' if set and valid, else the value returned by
  * 'date("e")' if valid, else the default specified if the global
  * constant '$GLOBALS["_DATE_TIMEZONE_DEFAULT"]', which if itself
  * left unset, defaults to "UTC".
  *
  * N.B. this is a private method; to set the time zone to the
  * default publicly you should call 'setTZByID()', that is, with no
  * parameter (or a parameter of null).
  *
  * @return   void
  * @access   private
  * @since    Method available since Release 1.5.0
  */
 function _setTZToDefault()
 {
     if (function_exists('version_compare') && version_compare(phpversion(), "5.1.0", ">=") && (Date_TimeZone::isValidID($hs_id = ini_get("date.timezone")) || Date_TimeZone::isValidID($hs_id = date("e")))) {
         $this->tz = new Date_TimeZone($hs_id);
     } else {
         $this->tz = Date_TimeZone::getDefault();
     }
 }
Exemplo n.º 5
0
<?php

require_once 'Date.php';
$_DATE_TIMEZONE_DEFAULT = 'Pacific/Chatham';
$tz = Date_TimeZone::getDefault();
if ($tz->id != $_DATE_TIMEZONE_DEFAULT && $tz->id != 'Pacific/Chatham') {
    echo "setDefault Failed\n";
}
Date_TimeZone::setDefault('CST');
$default = 'EST';
$tz = Date_TimeZone::getDefault();
if ($tz->id != $_DATE_TIMEZONE_DEFAULT && $tz->id != 'EST') {
    echo "setDefault Failed\n";
}
Exemplo n.º 6
0
 /**
  * Get the user's preferred timezone
  *
  * @return   string  name of the timezone
  * @static
  *
  */
 public static function getUserTimeZone()
 {
     global $_CONF, $_USER;
     // handle like the theme cookie, i.e. use if user is not logged in
     if (isset($_COOKIE[$_CONF['cookie_tzid']]) && empty($_USER['tzid'])) {
         $_USER['tzid'] = $_COOKIE[$_CONF['cookie_tzid']];
     }
     if (!empty($_USER['tzid'])) {
         $timezone = $_USER['tzid'];
     } elseif (!empty($_CONF['timezone'])) {
         $timezone = $_CONF['timezone'];
     } elseif (function_exists('date_default_timezone_get')) {
         $timezone = @date_default_timezone_get();
     } else {
         require_once 'Date/TimeZone.php';
         $tz_obj = Date_TimeZone::getDefault();
         $timezone = $tz_obj->id;
     }
     return $timezone;
 }
Exemplo n.º 7
0
 /**
  * Return a string expression of the server time zone
  *
  * @return           mixed  '(+|-)\d\d:\d\d' or false
  * @see              PEAR Date/TimeZone.php
  */
 private function getTimezoneStr()
 {
     global $_CONF;
     static $retval = null;
     if ($retval === null) {
         if (isset($_CONF['timezone'])) {
             $timezone = $_CONF['timezone'];
             // Load Date_TimeZone class
             Date_TimeZone::getDefault();
             if (array_key_exists($timezone, $GLOBALS['_DATE_TIMEZONE_DATA'])) {
                 $offset = $GLOBALS['_DATE_TIMEZONE_DATA'][$timezone]['offset'];
                 if ($offset >= 0) {
                     $retval = '+';
                 } else {
                     $retval = '-';
                     $offset = -$offset;
                 }
                 $hour = floor($offset / 3600000);
                 $min = ($offset - 3600000 * $hour) % 60000;
                 $retval .= sprintf('%02d:%02d', $hour, $min);
             } else {
                 COM_errorLog(__METHOD__ . ': $_CONF[\'timezone\'] is wrong: ' . $_CONF['timezone']);
                 $retval = false;
             }
         } else {
             $retval = false;
         }
     }
     return $retval;
 }
Exemplo n.º 8
0
 /**
  * Sets the time zone of this date with the given time zone id
  *
  * Sets the time zone of this date with the given
  * time zone id, or to the system default if the
  * given id is invalid. Does not alter the date/time,
  * only assigns a new time zone.  For conversion, use
  * convertTZ().
  *
  * @access public
  * @param string id a time zone id
  */
 function setTZbyID($id)
 {
     if (Date_TimeZone::isValidID($id)) {
         $this->tz = new Date_TimeZone($id);
     } else {
         $this->tz = Date_TimeZone::getDefault();
     }
 }
Exemplo n.º 9
0
 /**
  * Provide a list of available timezones
  *
  * @return   array   array of (timezone-short-name, timezone-long-name) pairs
  */
 public static function listAvailableTimeZones()
 {
     $timezones = array();
     // use only timezones that contain one of these
     $useOnly = array('Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific', 'UTC');
     // check if we can use the DateTimeZone class
     $useDateTimeZone = false;
     if (class_exists('DateTimeZone') && class_exists('ReflectionClass')) {
         $rc = new ReflectionClass('DateTimeZone');
         if ($rc->hasMethod('listAbbreviations')) {
             $useDateTimeZone = true;
         }
     }
     if ($useDateTimeZone) {
         $T = DateTimeZone::listAbbreviations();
         foreach ($T as $tzId => $entries) {
             $shortName = strtoupper($tzId);
             foreach ($entries as $data) {
                 $tzCheck = explode('/', $data['timezone_id']);
                 if (!in_array($tzCheck[0], $useOnly)) {
                     continue;
                 }
                 $hours = $data['offset'] / 3600;
                 $hours = (int) ($hours * 100) / 100;
                 if ($hours > 0) {
                     $hours = "+{$hours}";
                 }
                 $tzCode = str_replace('_', ' ', $data['timezone_id']);
                 $tzCode = htmlspecialchars($tzCode);
                 $formattedTimezone = "{$hours}, {$shortName} ({$tzCode})";
                 $timezones[$data['timezone_id']] = $formattedTimezone;
             }
         }
     } else {
         // DateTimeZone not available - use PEAR Date class
         // Load Date_TimeZone class
         Date_TimeZone::getDefault();
         $T = $GLOBALS['_DATE_TIMEZONE_DATA'];
         foreach ($T as $tzId => $tDetails) {
             $tzCheck = explode('/', $tzId);
             if (!in_array($tzCheck[0], $useOnly)) {
                 continue;
             }
             if (!empty($tzCheck[1]) && strpos($tzCheck[1], 'Riyadh') === 0) {
                 // these time zones are based on solar time and not widely
                 // supported - skip
                 continue;
             }
             $tzCode = str_replace('_', ' ', $tzId);
             $tzCode = htmlspecialchars($tzCode);
             $hours = $tDetails['offset'] / (3600 * 1000);
             $hours = (int) ($hours * 100) / 100;
             if ($hours > 0) {
                 $hours = "+{$hours}";
             }
             $formattedTimezone = "{$hours}, {$tDetails['shortname']} ({$tzCode})";
             $timezones[$tzId] = $formattedTimezone;
         }
     }
     uasort($timezones, array('TimeZoneConfig', '_sort_by_timezone'));
     return $timezones;
 }
Exemplo n.º 10
0
 /**
  * Converts this date to a new time zone, given a valid time zone ID
  *
  * Converts this date to a new time zone, given a valid time zone ID
  * WARNING: This may not work correctly if your system does not allow
  * putenv() or if localtime() does not work in your environment.  See
  * Date::TimeZone::inDaylightTime() for more information.
  *
  * @access public
  * @param string id a time zone id
  */
 function convertTZbyID($id)
 {
     if (Date_TimeZone::isValidID($id)) {
         $tz = new Date_TimeZone($id);
     } else {
         $timezone = new Date_TimeZone('UTC');
         $tz = $timezone->getDefault();
     }
     $this->convertTZ($tz);
 }