示例#1
1
 public static function run()
 {
     spl_autoload_register(['Bootstrap', 'autoload']);
     putenv('LANG=en_US.UTF-8');
     setlocale(LC_CTYPE, 'en_US.UTF-8');
     date_default_timezone_set(@date_default_timezone_get());
     session_start();
     $session = new Session($_SESSION);
     $request = new Request($_REQUEST);
     $setup = new Setup($request->query_boolean('refresh', false));
     $context = new Context($session, $request, $setup);
     if ($context->is_api_request()) {
         (new Api($context))->apply();
     } else {
         if ($context->is_info_request()) {
             $public_href = $setup->get('PUBLIC_HREF');
             $x_head_tags = $context->get_x_head_html();
             require __DIR__ . '/pages/info.php';
         } else {
             $public_href = $setup->get('PUBLIC_HREF');
             $x_head_tags = $context->get_x_head_html();
             $fallback_html = (new Fallback($context))->get_html();
             require __DIR__ . '/pages/index.php';
         }
     }
 }
 public function __construct()
 {
     $this->fmt = new IntlDateFormatter('nl_BE', IntlDateFormatter::FULL, IntlDateFormatter::FULL, date_default_timezone_get(), IntlDateFormatter::GREGORIAN, 'd MMMM yyyy');
     $this->fmtWeekDayLong = new IntlDateFormatter('nl_BE', IntlDateFormatter::FULL, IntlDateFormatter::FULL, date_default_timezone_get(), IntlDateFormatter::GREGORIAN, 'EEEE');
     $this->fmtWeekDayShort = new IntlDateFormatter('nl_BE', IntlDateFormatter::FULL, IntlDateFormatter::FULL, date_default_timezone_get(), IntlDateFormatter::GREGORIAN, 'EEEEEE');
     $this->fmtTime = new IntlDateFormatter('nl_BE', IntlDateFormatter::FULL, IntlDateFormatter::FULL, date_default_timezone_get(), IntlDateFormatter::GREGORIAN, 'HH:mm');
 }
示例#3
0
文件: Core.php 项目: stler/NMFrame
 /**
  * Gets the default timezone to be used by the date filter.
  *
  * @return DateTimeZone The default timezone currently in use
  */
 public function getTimezone()
 {
     if (null === $this->timezone) {
         $this->timezone = new DateTimeZone(date_default_timezone_get());
     }
     return $this->timezone;
 }
示例#4
0
 /**
  * @param array $components
  */
 private function mapComponents(array $components)
 {
     foreach ($components as $component) {
         $this->components[(string) $component] = $component;
     }
     $this->timezone = date_default_timezone_get();
 }
 /**
  * {@inheritDoc}
  */
 protected function configure()
 {
     $this->addOption('input_timezone', date_default_timezone_get());
     $this->addOption('output_timezone', date_default_timezone_get());
     $this->addOption('format', 'Y-m-d H:i:s');
     parent::configure();
 }
示例#6
0
文件: date.php 项目: nasumi/fuel
	public static function _init()
	{
		static::$server_gmt_offset	= \Config::get('server_gmt_offset', 0);

		// Set the default timezone
		static::$default_timezone	= date_default_timezone_get();

		// Ugly temporary windows fix because windows doesn't support strptime()
		// Better fix will accept custom pattern parsing but only parse numeric input on windows servers
		if ( ! function_exists('strptime') && ! function_exists('Fuel\Core\strptime'))
		{
			function strptime($input, $format)
			{
				$ts = strtotime($input);
				return array(
					'tm_year'	=> date('Y', $ts),
					'tm_mon'	=> date('n', $ts),
					'tm_mday'	=> date('j', $ts),
					'tm_hour'	=> date('H', $ts),
					'tm_min'	=> date('i', $ts),
					'tm_sec'	=> date('s', $ts)
				);
				// This really is some fugly code, but someone at PHP HQ decided strptime should
				// output this awful array instead of a timestamp LIKE EVERYONE ELSE DOES!!!
			}
		}
	}
示例#7
0
 /**
  * Initialize the timezone.
  *
  * This function should be called before any calls to date().
  *
  * @author Olav Morken, UNINETT AS <*****@*****.**>
  */
 public static function initTimezone()
 {
     static $initialized = false;
     if ($initialized) {
         return;
     }
     $initialized = true;
     $globalConfig = \SimpleSAML_Configuration::getInstance();
     $timezone = $globalConfig->getString('timezone', null);
     if ($timezone !== null) {
         if (!date_default_timezone_set($timezone)) {
             throw new \SimpleSAML_Error_Exception('Invalid timezone set in the "timezone" option in config.php.');
         }
         return;
     }
     // we don't have a timezone configured
     /*
      * The date_default_timezone_get() function is likely to cause a warning.
      * Since we have a custom error handler which logs the errors with a backtrace,
      * this error will be logged even if we prefix the function call with '@'.
      * Instead we temporarily replace the error handler.
      */
     set_error_handler(function () {
         return true;
     });
     $serverTimezone = date_default_timezone_get();
     restore_error_handler();
     // set the timezone to the default
     date_default_timezone_set($serverTimezone);
 }
示例#8
0
/**
* Fix basic php issues and check version
*/
function initialBasicFixes()
{
    /**
     * bypass date & timezone-related warnings with php 5.1
     */
    if (function_exists('date_default_timezone_set')) {
        $tz = @date_default_timezone_get();
        date_default_timezone_set($tz);
    }
    ini_set('zend.ze1_compatibility_mode', 0);
    ini_set("pcre.backtrack_limit", -1);
    # fix 5.2.0 prce bug with render_wiki
    if (function_exists('mb_internal_encoding')) {
        mb_internal_encoding("UTF-8");
    }
    #ini_set("mbstring.func_overload", 2);
    /**
     * add rough php-version check to at least avoid parsing errors.
     * fine version-check follows further down
     */
    if (phpversion() < "5.0.0") {
        echo "Sorry, but Streber requires php5 or higher.";
        exit;
    }
}
示例#9
0
文件: Date.php 项目: acp3/setup
 /**
  * Date constructor.
  *
  * @param \ACP3\Core\Date\DateTranslator $dateTranslator
  */
 public function __construct(DateTranslator $dateTranslator)
 {
     $this->dateTranslator = $dateTranslator;
     $defaultTimeZone = date_default_timezone_get();
     $settings = ['date_format_long' => 'd.m.y, H:i', 'date_format_short' => 'd.m.y', 'time_zone' => !empty($defaultTimeZone) ? $defaultTimeZone : 'UTC'];
     $this->setFormatAndTimeZone($settings);
 }
示例#10
0
function updateTime()
{
    // date_default_timezone_set('America/New_York');
    echo date_default_timezone_get() . "<br>";
    $date = date('m/d/Y h:i:s a', time());
    echo getTime();
}
示例#11
0
 private function _formatVarAsJSON($var)
 {
     if (is_scalar($var) || is_null($var)) {
         return $var;
     }
     if (is_array($var)) {
         foreach ($var as $index => $value) {
             $var[$index] = $this->_formatVarAsJSON($value);
         }
         return $var;
     }
     if (is_object($var)) {
         $this->_paramIndex++;
         switch (get_class($var)) {
             case "MongoId":
                 $this->_jsonParams[$this->_paramIndex] = 'ObjectId("' . $var->__toString() . '")';
                 return $this->_param($this->_paramIndex);
             case "MongoDate":
                 $timezone = date_default_timezone_get();
                 date_default_timezone_set("UTC");
                 $this->_jsonParams[$this->_paramIndex] = "ISODate(\"" . date("Y-m-d", $var->sec) . "T" . date("H:i:s.", $var->sec) . $var->usec / 1000 . "Z\")";
                 date_default_timezone_set($timezone);
                 return $this->_param($this->_paramIndex);
             default:
                 if (method_exists($var, "__toString")) {
                     return $var->__toString();
                 }
                 return '<unknown type>';
         }
     }
 }
示例#12
0
文件: SitemapTest.php 项目: noose/zf2
    protected function setUp()
    {
        $this->_originaltimezone = date_default_timezone_get();
    	date_default_timezone_set('Europe/Berlin');

        if (isset($_SERVER['SERVER_NAME'])) {
            $this->_oldServer['SERVER_NAME'] = $_SERVER['SERVER_NAME'];
        }

        if (isset($_SERVER['SERVER_PORT'])) {
            $this->_oldServer['SERVER_PORT'] = $_SERVER['SERVER_PORT'];
        }

        if (isset($_SERVER['REQUEST_URI'])) {
            $this->_oldServer['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
        }

        $_SERVER['SERVER_NAME'] = 'localhost';
        $_SERVER['SERVER_PORT'] = 80;
        $_SERVER['REQUEST_URI'] = '/';

        $this->_front = \Zend\Controller\Front::getInstance();
        $this->_oldRequest = $this->_front->getRequest();
        $this->_oldRouter = $this->_front->getRouter();

        $this->_front->resetInstance();
        $this->_front->setRequest(new Request\Http());
        $this->_front->getRouter()->addDefaultRoutes();

        parent::setUp();

        $this->_helper->setFormatOutput(true);
    }
 public function setUp()
 {
     // Set timezone to support timestamp->date conversion.
     $this->originalTZ = date_default_timezone_get();
     date_default_timezone_set('Pacific/Auckland');
     parent::setUp();
 }
示例#14
0
 /**
  * Sets date/time
  *
  * @param \DateTime|string $datetime
  * @param string           $fromFormat
  * @param string           $timezone
  */
 public function setDateTime($datetime = '', $fromFormat = 'Y-m-d H:i:s', $timezone = 'local')
 {
     if ($timezone == 'local') {
         $timezone = date_default_timezone_get();
     } elseif (empty($timezone)) {
         $timezone = 'UTC';
     }
     $this->format = empty($fromFormat) ? 'Y-m-d H:i:s' : $fromFormat;
     $this->timezone = $timezone;
     $this->utc = new \DateTimeZone('UTC');
     $this->local = new \DateTimeZone(date_default_timezone_get());
     if ($datetime instanceof \DateTime) {
         $this->datetime = $datetime;
         $this->string = $this->datetime->format($fromFormat);
     } elseif (empty($datetime)) {
         $this->datetime = new \DateTime('now', new \DateTimeZone($this->timezone));
         $this->string = $this->datetime->format($fromFormat);
     } elseif ($fromFormat == null) {
         $this->string = $datetime;
         $this->datetime = new \DateTime($datetime, new \DateTimeZone($this->timezone));
     } else {
         $this->string = $datetime;
         $this->datetime = \DateTime::createFromFormat($this->format, $this->string, new \DateTimeZone($this->timezone));
         if ($this->datetime === false) {
             //the format does not match the string so let's attempt to fix that
             $this->string = date($this->format, strtotime($datetime));
             $this->datetime = \DateTime::createFromFormat($this->format, $this->string);
         }
     }
 }
 /**
  * Accepts an array of $date_durations and removes any falling on the dates listed
  * within $exclusion_dates.
  *
  * Both parameters are arrays of arrays, each inner array or "date duration" taking the
  * following form:
  *
  *     [ 'timestamp' => int,
  *       'duration'  => int  ]
  *
  * In the case of exclusions, duration will always be zero as custom exclusions do
  * not currently support custom durations, so that element is ignored during comparison.
  *
  * @param array $date_durations
  * @param array $exclusion_dates
  *
  * @return array
  */
 public function remove_exclusions(array $date_durations, array $exclusion_dates)
 {
     $date_default_timezone = date_default_timezone_get();
     $timezone_identifier = $this->timezone_string;
     $timezone_slip = 0;
     $matches = array();
     preg_match('/^UTC(\\+|-)+(\\d+)+(\\.(\\d+)*)*/', $this->timezone_string, $matches);
     if ($matches) {
         $timezone_identifier = 'UTC';
         $signum = $matches[1];
         $hrs = intval($matches[2]) * 3600;
         $minutes = floatval(empty($matches[3]) ? 0 : $matches[3]) * 3600;
         $timezone_slip = intval($signum . ($hrs + $minutes));
     }
     date_default_timezone_set($timezone_identifier);
     $exclusion_timestamps = array();
     // 24hrs in seconds -1 second
     $almost_one_day = 86399;
     foreach ($exclusion_dates as $exclusion) {
         $start = strtotime('midnight', $exclusion['timestamp']) + $timezone_slip;
         $exclusion_timestamps[] = array('start' => $start, 'end' => $start + $almost_one_day);
     }
     foreach ($date_durations as $key => $date_duration) {
         foreach ($exclusion_timestamps as $exclusion_timestamp) {
             if ($exclusion_timestamp['start'] <= $date_duration['timestamp'] && $date_duration['timestamp'] <= $exclusion_timestamp['end']) {
                 unset($date_durations[$key]);
             }
         }
     }
     $date_durations = array_values($date_durations);
     date_default_timezone_set($date_default_timezone);
     return $date_durations;
 }
示例#16
0
 /**
  * Set default options for this instance
  *
  * @param array $options
  */
 public function __construct($options = array())
 {
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     } elseif (!is_array($options)) {
         $options = func_get_args();
         $temp['baseValue'] = array_shift($options);
         if (!empty($options)) {
             $temp['step'] = array_shift($options);
         }
         if (!empty($options)) {
             $temp['format'] = array_shift($options);
         }
         if (!empty($options)) {
             $temp['timezone'] = array_shift($options);
         }
         $options = $temp;
     }
     if (!isset($options['step'])) {
         $options['step'] = new DateInterval('P1D');
     }
     if (!isset($options['timezone'])) {
         $options['timezone'] = new DateTimeZone(date_default_timezone_get());
     }
     parent::__construct($options);
 }
示例#17
0
 public function setUp()
 {
     $this->dateTime = strtotime('2009-02-13 23:31:30GMT');
     // a friday
     $this->defaultTimezone = date_default_timezone_get();
     date_default_timezone_set('GMT');
 }
 /**
  * {@inheritDoc}
  */
 public function getConfigTreeBuilder()
 {
     $treeBuilder = new TreeBuilder();
     $rootNode = $treeBuilder->root('sonata_intl');
     $rootNode->children()->scalarNode('locale')->defaultValue(false)->end()->arrayNode('timezone')->addDefaultsIfNotSet()->children()->scalarNode('service')->end()->arrayNode('detectors')->prototype('scalar')->end()->end()->scalarNode('default')->defaultValue(date_default_timezone_get())->end()->arrayNode('locales')->defaultValue(array())->useAttributeAsKey('name')->prototype('scalar')->end()->end()->end()->end();
     return $treeBuilder;
 }
示例#19
0
 public function setUp()
 {
     $this->originaltimezone = date_default_timezone_get();
     // Set timezone to avoid "It is not safe to rely on the system's timezone settings."
     // message if timezone is not set within php.ini
     date_default_timezone_set('GMT');
 }
 public function convertPHPFormatDateToISOFormatDate($inputPHPFormat, $date)
 {
     $dateFormat = new sfDateFormat();
     try {
         $symfonyPattern = $this->__getSymfonyDateFormatPattern($inputPHPFormat);
         $dateParts = $dateFormat->getDate($date, $symfonyPattern);
         if (is_array($dateParts) && isset($dateParts['year']) && isset($dateParts['mon']) && isset($dateParts['mday'])) {
             $day = $dateParts['mday'];
             $month = $dateParts['mon'];
             $year = $dateParts['year'];
             // Additional check done for 3 digit years, or more than 4 digit years
             if (checkdate($month, $day, $year) && $year >= 1000 && $year <= 9999) {
                 $dateTime = new DateTime();
                 $dateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
                 $dateTime->setDate($year, $month, $day);
                 $date = $dateTime->format('Y-m-d');
                 return $date;
             } else {
                 return "Invalid date";
             }
         }
     } catch (Exception $e) {
         return "Invalid date";
     }
     return null;
 }
示例#21
0
 /** 
  * Find the local time at the event...
  * @param $evt_offset integer Event's offset from UTC
  */
 private function _getEvtTime($evt_offset)
 {
     $here = new DateTimeZone(date_default_timezone_get());
     $hoffset = $here->getOffset(new DateTime("now", $here));
     $off = time() - $hoffset + $evt_offset * 3600;
     return $off;
 }
示例#22
0
    /**
     * Renders a date time widget.
     *
     * @param array $data Data to render with.
     * @param \Cake\View\Form\ContextInterface $context The current form context.
     * @return string A generated select box.
     * @throws \RuntimeException When option data is invalid.
     */
    public function render(array $data, ContextInterface $context)
    {
        $id = $data['id'];
        $name = $data['name'];
        $val = $data['val'];
        $type = $data['type'];
        $required = $data['required'] ? 'required' : '';
        $disabled = isset($data['disabled']) && $data['disabled'] ? 'disabled' : '';
        $role = isset($data['role']) ? $data['role'] : 'datetime-picker';
        $format = null;
        $locale = isset($data['locale']) ? $data['locale'] : I18n::locale();
        $timezoneAware = Configure::read('CrudView.timezoneAwareDateTimeWidget');
        $timestamp = null;
        $timezoneOffset = null;
        if (isset($data['data-format'])) {
            $format = $this->_convertPHPToMomentFormat($data['data-format']);
        }
        if (!$val instanceof DateTimeInterface && !empty($val)) {
            $val = $type === 'date' ? Time::parseDate($val) : Time::parseDateTime($val);
        }
        if ($val) {
            if ($timezoneAware) {
                $timestamp = $val->format('U');
                $dateTimeZone = new DateTimeZone(date_default_timezone_get());
                $timezoneOffset = $dateTimeZone->getOffset($val) / 60;
            }
            $val = $val->format($type === 'date' ? 'Y-m-d' : 'Y-m-d H:i:s');
        }
        if (!$format) {
            $format = $type === 'date' ? 'L' : 'L LT';
        }
        $widget = <<<html
            <div class="input-group {$type}">
                <input
                    type="text"
                    class="form-control"
                    name="{$name}"
                    value="{$val}"
                    id="{$id}"
                    role="{$role}"
                    data-locale="{$locale}"
                    data-format="{$format}"
html;
        if ($timezoneAware && isset($timestamp, $timezoneOffset)) {
            $widget .= <<<html
                    data-timestamp="{$timestamp}"
                    data-timezone-offset="{$timezoneOffset}"
html;
        }
        $widget .= <<<html
                    {$required}
                    {$disabled}
                />
                <label for="{$id}" class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </label>
            </div>
html;
        return $widget;
    }
示例#23
0
文件: Ajax.php 项目: mahdidham/rsbpjs
 public function buat_SEP()
 {
     $timezone = date_default_timezone_get();
     date_default_timezone_set('UTC');
     $timestamp = strval(time() - strtotime('1970-01-01 00:00:00'));
     //cari timestamp
     $signature = hash_hmac('sha256', '27952' . '&' . $timestamp, 'rsm32h1', true);
     $encoded_signature = base64_encode($signature);
     $http_header = array('Accept: application/json', 'Content-type: application/xml', 'X-cons-id: 27952', 'X-timestamp: ' . $timestamp, 'X-signature: ' . $encoded_signature);
     date_default_timezone_set($timezone);
     //nama variabel sesuai dengan nama di xml
     $noMR = $this->input->post('no_cm');
     $noKartu = $this->input->post('no_bpjs');
     $noRujukan = $this->input->post('no_sjp');
     $ppkRujukan = $this->input->post('ppk_rujukan');
     $jnsPelayanan = $this->input->post('pelayanan');
     $klsRawat = $this->input->post('kelas_pasien');
     $diagAwal = $this->input->post('nm_diagnosa');
     $poliTujuan = $this->input->post('nm_poli');
     $catatan = $this->input->post('catatan');
     $user = '******';
     $ppkPelayanan = '0601R001';
     $tglSep = date('Y-m-d H:i:s');
     $tglRujukan = date('Y-m-d H:i:s');
     $data = '<request><data><t_sep>' . '<noKartu>' . $noKartu . '</noKartu>' . '<tglSep>' . $tglSep . '</tglSep>' . '<tglRujukan>' . $tglRujukan . '</tglRujukan>' . '<noRujukan>' . $noRujukan . '</noRujukan>' . '<ppkRujukan>' . $ppkRujukan . '</ppkRujukan>' . '<ppkPelayanan>' . $ppkPelayanan . '</ppkPelayanan>' . '<jnsPelayanan>' . $jnsPelayanan . '</jnsPelayanan>' . '<catatan>' . $catatan . '</catatan>' . '<diagAwal>' . $diagAwal . '</diagAwal>' . '<poliTujuan>' . $poliTujuan . '</poliTujuan>' . '<klsRawat>' . $klsRawat . '</klsRawat>' . '<user>' . $user . '</user>' . '<noMR>' . $noMR . '</noMR>' . '</t_sep></data></request>';
     $ch = curl_init('http://api.asterix.co.id/SepWebRest/sep/create/');
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $http_header);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $result = curl_exec($ch);
     curl_close($ch);
     $sep = json_decode($result)->response;
     echo $sep;
 }
示例#24
0
 function testTimezones()
 {
     $default = date_default_timezone_get();
     date_default_timezone_set('Europe/Amsterdam');
     $this->testParseHTTPDate();
     date_default_timezone_set($default);
 }
示例#25
0
 public function __construct()
 {
     parent::__construct();
     // PHP 5.3 ask for timezone, and throw a warning whenever it is not available
     // so, just give this one :)
     $timezone = @date_default_timezone_get();
     if (!isset($timezone) || $timezone == '') {
         $timezone = @ini_get('date.timezone');
     }
     if (!isset($timezone) || $timezone == '') {
         $timezone = 'UTC';
     }
     date_default_timezone_set($timezone);
     // load helpers and libraries
     $this->load->helper('url');
     $this->load->helper('html');
     $this->load->helper('form');
     $this->load->helper('string');
     $this->load->library('user_agent');
     $this->load->driver('session');
     $this->load->helper('cms_helper');
     $this->load->library('form_validation');
     $this->load->database();
     // accessing file is faster than accessing database
     // but I think accessing variable is faster than both of them
     $this->__cms_model_properties = array('session' => array(), 'language_dictionary' => array(), 'config' => array());
 }
示例#26
0
 /**
  * @preserveGlobalState disabled
  * @runInSeparateProcess
  */
 public function test_reload()
 {
     date_default_timezone_set('Europe/London');
     $this->config->reload(array('timezone_setting' => 'UTC', 'bar' => 'foo'));
     $this->assertEquals('UTC', date_default_timezone_get());
     $this->assertEquals('foo', $this->config->get('bar'));
 }
示例#27
0
 public static function _init()
 {
     static::$server_gmt_offset = \Config::get('server_gmt_offset', 0);
     static::$display_timezone = \Config::get('default_timezone') ?: date_default_timezone_get();
     // Ugly temporary windows fix because windows doesn't support strptime()
     // It attempts conversion between glibc style formats and PHP's internal style format (no 100% match!)
     if (!function_exists('strptime') && !function_exists('Fuel\\Core\\strptime')) {
         function strptime($input, $format)
         {
             // convert the format string from glibc to date format (where possible)
             $new_format = str_replace(array('%a', '%A', '%d', '%e', '%j', '%u', '%w', '%U', '%V', '%W', '%b', '%B', '%h', '%m', '%C', '%g', '%G', '%y', '%Y', '%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r', '%R', '%S', '%T', '%X', '%z', '%Z', '%c', '%D', '%F', '%s', '%x', '%n', '%t', '%%'), array('D', 'l', 'd', 'j', 'N', 'z', 'w', '[^^]', 'W', '[^^]', 'M', 'F', 'M', 'm', '[^^]', 'Y', 'o', 'y', 'Y', 'H', 'G', 'h', 'g', 'i', 'A', 'a', 'H:i:s A', 'H:i', 's', 'H:i:s', '[^^]', 'O', 'T ', '[^^]', 'm/d/Y', 'Y-m-d', 'U', '[^^]', "\n", "\t", '%'), $format);
             // parse the input
             $parsed = date_parse_from_format($new_format, $input);
             // parse succesful?
             if (is_array($parsed) and empty($parsed['errors'])) {
                 return array('tm_year' => $parsed['year'] - 1900, 'tm_mon' => $parsed['month'] - 1, 'tm_mday' => $parsed['day'], 'tm_hour' => $parsed['hour'] ?: 0, 'tm_min' => $parsed['minute'] ?: 0, 'tm_sec' => $parsed['second'] ?: 0);
             } else {
                 $masks = array('%d' => '(?P<d>[0-9]{2})', '%m' => '(?P<m>[0-9]{2})', '%Y' => '(?P<Y>[0-9]{4})', '%H' => '(?P<H>[0-9]{2})', '%M' => '(?P<M>[0-9]{2})', '%S' => '(?P<S>[0-9]{2})');
                 $rexep = "#" . strtr(preg_quote($format), $masks) . "#";
                 if (!preg_match($rexep, $input, $result)) {
                     return false;
                 }
                 return array("tm_sec" => isset($result['S']) ? (int) $result['S'] : 0, "tm_min" => isset($result['M']) ? (int) $result['M'] : 0, "tm_hour" => isset($result['H']) ? (int) $result['H'] : 0, "tm_mday" => isset($result['d']) ? (int) $result['d'] : 0, "tm_mon" => isset($result['m']) ? $result['m'] ? $result['m'] - 1 : 0 : 0, "tm_year" => isset($result['Y']) ? $result['Y'] > 1900 ? $result['Y'] - 1900 : 0 : 0);
             }
         }
         // This really is some fugly code, but someone at PHP HQ decided strptime should
         // output this awful array instead of a timestamp LIKE EVERYONE ELSE DOES!!!
     }
 }
示例#28
0
function qa_initialize_php()
{
    if (qa_php_version_below('4.3')) {
        qa_fatal_error('This requires PHP 4.3 or later');
    }
    error_reporting(E_ALL);
    // be ultra-strict about error checking
    @ini_set('magic_quotes_runtime', 0);
    @setlocale(LC_CTYPE, 'C');
    // prevent strtolower() et al affecting non-ASCII characters (appears important for IIS)
    if (function_exists('date_default_timezone_set') && function_exists('date_default_timezone_get')) {
        @date_default_timezone_set(@date_default_timezone_get());
    }
    // prevent PHP notices where default timezone not set
    if (ini_get('register_globals')) {
        $checkarrays = array('_ENV', '_GET', '_POST', '_COOKIE', '_SERVER', '_FILES', '_REQUEST', '_SESSION');
        // unregister globals if they're registered
        $keyprotect = array_flip(array_merge($checkarrays, array('GLOBALS')));
        foreach ($checkarrays as $checkarray) {
            if (isset(${$checkarray}) && is_array(${$checkarray})) {
                foreach (${$checkarray} as $checkkey => $checkvalue) {
                    if (isset($keyprotect[$checkkey])) {
                        qa_fatal_error('My superglobals are not for overriding');
                    } else {
                        unset($GLOBALS[$checkkey]);
                    }
                }
            }
        }
    }
}
示例#29
0
文件: date.php 项目: akksi/jcg
 /**
  * Constructor.
  *
  * @param	string	String in a format accepted by strtotime(), defaults to "now".
  * @param	mixed	Time zone to be used for the date.
  * @return	void
  * @since	1.5
  *
  * @throws	JException
  */
 public function __construct($date = 'now', $tz = null)
 {
     // Create the base GMT and server time zone objects.
     if (empty(self::$gmt) || empty(self::$stz)) {
         self::$gmt = new DateTimeZone('GMT');
         self::$stz = new DateTimeZone(@date_default_timezone_get());
     }
     // If the time zone object is not set, attempt to build it.
     if (!$tz instanceof DateTimeZone) {
         if ($tz === null) {
             $tz = self::$gmt;
         } elseif (is_numeric($tz)) {
             // Translate from offset.
             $tz = new DateTimeZone(self::$offsets[(string) $tz]);
         } elseif (is_string($tz)) {
             $tz = new DateTimeZone($tz);
         }
     }
     // If the date is numeric assume a unix timestamp and convert it.
     date_default_timezone_set('UTC');
     $date = is_numeric($date) ? date('c', $date) : $date;
     // Call the DateTime constructor.
     parent::__construct($date, $tz);
     // Set the timezone object for access later.
     $this->_tz = $tz;
 }
示例#30
0
 /**
  * Changes the default PHP time/date functions timezone.
  *
  * @param string $timezone Valid timezone code.
  *
  * @return bool FALSE if the $timezone isn't valid, or TRUE otherwise.
  */
 public static function setEnvironmentTimezone($timezone)
 {
     if (!$timezone) {
         $timezone = date_default_timezone_get();
     }
     return date_default_timezone_set($timezone);
 }