⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 date.php

📁 Bug tracker, and reporter.
💻 PHP
📖 第 1 页 / 共 5 页
字号:
<?php/** * Zend Framework * * LICENSE * * This source file is subject to the new BSD license that is bundled * with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://framework.zend.com/license/new-bsd * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@zend.com so we can send you a copy immediately. * * @category   Zend * @package    Zend_Date * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) * @version    $Id: Date.php 8943 2008-03-20 21:43:37Z thomas $ * @license    http://framework.zend.com/license/new-bsd     New BSD License *//** * Include needed Date classes */require_once 'Zend/Date/DateObject.php';require_once 'Zend/Locale.php';require_once 'Zend/Locale/Format.php';require_once 'Zend/Locale/Math.php';/** * @category   Zend * @package    Zend_Date * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) * @license    http://framework.zend.com/license/new-bsd     New BSD License */class Zend_Date extends Zend_Date_DateObject {    private   $_Locale  = null;    // Fractional second variables    private $_Fractional = 0;    private $_Precision  = 3;    private static $_Options = array(        'format_type'  => 'iso',      // format for date strings 'iso' or 'php'        'fix_dst'      => true,       // fix dst on summer/winter time change        'extend_month' => false,      // false - addMonth like SQL, true like excel        'cache'        => null,       // cache to set        'timesync'     => null        // timesync server to set    );    // Class wide Date Constants    // day formats    const DAY            = 'DAY';            // d - 2 digit day of month, 01-31    const DAY_SHORT      = 'DAY_SHORT';      // j - 1,2 digit day of month, 1-31    const DAY_SUFFIX     = 'DAY_SUFFIX';     // S - english suffix day of month, st-th    const DAY_OF_YEAR    = 'DAY_OF_YEAR';    // z - Number of day of year    const WEEKDAY        = 'WEEKDAY';        // l - full day name - locale aware, Monday - Sunday    const WEEKDAY_SHORT  = 'WEEKDAY_SHORT';  // --- 3 letter day of week - locale aware, Mon-Sun    const WEEKDAY_NARROW = 'WEEKDAY_NARROW'; // --- 1 letter day name - locale aware, M-S    const WEEKDAY_NAME   = 'WEEKDAY_NAME';   // D - abbreviated day name, 1-3 letters - locale aware, Mon-Sun    const WEEKDAY_8601   = 'WEEKDAY_8601';   // N - digit weekday ISO 8601, 1-7 1 = monday, 7=sunday    const WEEKDAY_DIGIT  = 'WEEKDAY_DIGIT';  // w - weekday, 0-6 0=sunday, 6=saturday    // week formats    const WEEK           = 'WEEK';           // W - number of week ISO8601, 1-53    // month formats    const MONTH          = 'MONTH';          // m - 2 digit month, 01-12    const MONTH_SHORT    = 'MONTH_SHORT';    // n - 1 digit month, no leading zeros, 1-12    const MONTH_DAYS     = 'MONTH_DAYS';     // t - Number of days this month    const MONTH_NAME        = 'MONTH_NAME';         // F - full month name - locale aware, January-December    const MONTH_NAME_SHORT  = 'MONTH_NAME_SHORT';  // M - 3 letter monthname - locale aware, Jan-Dec    const MONTH_NAME_NARROW = 'MONTH_NAME_NARROW'; // --- 1 letter month name - locale aware, J-D    // year formats    const YEAR           = 'YEAR';           // Y - 4 digit year    const YEAR_SHORT     = 'YEAR_SHORT';     // y - 2 digit year, leading zeros 00-99    const YEAR_8601      = 'YEAR_8601';      // o - number of year ISO8601    const YEAR_SHORT_8601= 'YEAR_SHORT_8601';// --- 2 digit number of year ISO8601    const LEAPYEAR       = 'LEAPYEAR';       // L - is leapyear ?, 0-1    // time formats    const MERIDIEM       = 'MERIDIEM';       // A,a - AM/PM - locale aware, AM/PM    const SWATCH         = 'SWATCH';         // B - Swatch Internet Time    const HOUR           = 'HOUR';           // H - 2 digit hour, leading zeros, 00-23    const HOUR_SHORT     = 'HOUR_SHORT';     // G - 1 digit hour, no leading zero, 0-23    const HOUR_AM        = 'HOUR_AM';        // h - 2 digit hour, leading zeros, 01-12 am/pm    const HOUR_SHORT_AM  = 'HOUR_SHORT_AM';  // g - 1 digit hour, no leading zero, 1-12 am/pm    const MINUTE         = 'MINUTE';         // i - 2 digit minute, leading zeros, 00-59    const MINUTE_SHORT   = 'MINUTE_SHORT';   // --- 1 digit minute, no leading zero, 0-59    const SECOND         = 'SECOND';         // s - 2 digit second, leading zeros, 00-59    const SECOND_SHORT   = 'SECOND_SHORT';   // --- 1 digit second, no leading zero, 0-59    const MILLISECOND    = 'MILLISECOND';    // --- milliseconds    // timezone formats    const TIMEZONE_NAME  = 'TIMEZONE_NAME';  // e - timezone string    const DAYLIGHT       = 'DAYLIGHT';       // I - is Daylight saving time ?, 0-1    const GMT_DIFF       = 'GMT_DIFF';       // O - GMT difference, -1200 +1200    const GMT_DIFF_SEP   = 'GMT_DIFF_SEP';   // P - seperated GMT diff, -12:00 +12:00    const TIMEZONE       = 'TIMEZONE';       // T - timezone, EST, GMT, MDT    const TIMEZONE_SECS  = 'TIMEZONE_SECS';  // Z - timezone offset in seconds, -43200 +43200    // date strings    const ISO_8601       = 'ISO_8601';       // c - ISO 8601 date string    const RFC_2822       = 'RFC_2822';       // r - RFC 2822 date string    const TIMESTAMP      = 'TIMESTAMP';      // U - unix timestamp    // additional formats    const ERA            = 'ERA';            // --- short name of era, locale aware,    const ERA_NAME       = 'ERA_NAME';       // --- full name of era, locale aware,    const DATES          = 'DATES';          // --- standard date, locale aware    const DATE_FULL      = 'DATE_FULL';      // --- full date, locale aware    const DATE_LONG      = 'DATE_LONG';      // --- long date, locale aware    const DATE_MEDIUM    = 'DATE_MEDIUM';    // --- medium date, locale aware    const DATE_SHORT     = 'DATE_SHORT';     // --- short date, locale aware    const TIMES          = 'TIMES';          // --- standard time, locale aware    const TIME_FULL      = 'TIME_FULL';      // --- full time, locale aware    const TIME_LONG      = 'TIME_LONG';      // --- long time, locale aware    const TIME_MEDIUM    = 'TIME_MEDIUM';    // --- medium time, locale aware    const TIME_SHORT     = 'TIME_SHORT';     // --- short time, locale aware    const ATOM           = 'ATOM';           // --- DATE_ATOM    const COOKIE         = 'COOKIE';         // --- DATE_COOKIE    const RFC_822        = 'RFC_822';        // --- DATE_RFC822    const RFC_850        = 'RFC_850';        // --- DATE_RFC850    const RFC_1036       = 'RFC_1036';       // --- DATE_RFC1036    const RFC_1123       = 'RFC_1123';       // --- DATE_RFC1123    const RFC_3339       = 'RFC_3339';       // --- DATE_RFC3339    const RSS            = 'RSS';            // --- DATE_RSS    const W3C            = 'W3C';            // --- DATE_W3C    /**     * Generates the standard date object, could be a unix timestamp, localized date,     * string, integer, array and so on. Also parts of dates or time are supported     * Always set the default timezone: http://php.net/date_default_timezone_set     * For example, in your bootstrap: date_default_timezone_set('America/Los_Angeles');     * For detailed instructions please look in the docu.     *     * @param  string|integer|Zend_Date|array  $date    OPTIONAL Date value or value of date part to set     *                                                 ,depending on $part. If null the actual time is set     * @param  string                          $part    OPTIONAL Defines the input format of $date     * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input     * @return Zend_Date     * @throws Zend_Date_Exception     */    public function __construct($date = null, $part = null, $locale = null)    {        if (Zend_Locale::isLocale($date)) {            $locale = $date;            $date = null;            $part = null;        } else if (Zend_Locale::isLocale($part)) {            $locale = $part;            $part = null;        }        $this->setLocale($locale);        if (is_string($date) && defined("self::".$date)) {            $part = $date;            $date = null;        }        if (is_null($date)) {            $date = Zend_Date::now($locale);            if (($part !== null) && ($part !== Zend_Date::TIMESTAMP)) {                $date = $date->get($part);            }        }        if ($date instanceof Zend_TimeSync_Protocol) {            $date = $date->getInfo();            $date = $this->_getTime($date['offset']);            $part = null;        } else if (parent::$_defaultOffset != 0) {            $date = $this->_getTime(parent::$_defaultOffset);        }        // set the timezone and offset for $this        $zone = @date_default_timezone_get();        $this->setTimezone($zone);        // try to get timezone from date-string        $zone = $this->getTimezoneFromString($date);        $this->setTimezone($zone);        // set datepart        if (($part !== null && $part !== Zend_Date::TIMESTAMP) or (!is_numeric($date))) {            // switch off dst handling for value setting            $this->setUnixTimestamp($this->getGmtOffset());            $this->set($date, $part, $this->_Locale);            // DST fix            if (is_array($date) and array_key_exists('hour', $date)) {                $hour = $this->toString('H');                $hour = $date['hour'] - $hour;                if ($hour !== 0) {                    $this->addTimestamp($hour * 3600);                }            }        } else {            $this->setUnixTimestamp($date);        }    }    /**     * Sets class wide options, if no option was given, the actual set options will be returned     *     * @param  array  $options  Options to set     * @throws Zend_Date_Exception     * @return Options array if no option was given     */    public static function setOptions(array $options = array())    {        if (empty($options)) {            return self::$_Options;        }        foreach ($options as $name => $value) {            $name  = strtolower($name);            if (array_key_exists($name, self::$_Options)) {                switch($name) {                    case 'format_type' :                        if ((strtolower($value) != 'php') && (strtolower($value) != 'iso')) {                            require_once 'Zend/Date/Exception.php';                            throw new Zend_Date_Exception("Unknown format type ($value) for dates, only 'iso' and 'php' supported", $value);                        }                        break;                    case 'fix_dst' :                        if (!is_bool($value)) {                            require_once 'Zend/Date/Exception.php';                            throw new Zend_Date_Exception("'fix_dst' has to be boolean", $value);                        }                        break;                    case 'extend_month' :                        if (!is_bool($value)) {                            require_once 'Zend/Date/Exception.php';                            throw new Zend_Date_Exception("'extend_month' has to be boolean", $value);                        }                        break;                    case 'cache' :                        if (!$value instanceof Zend_Cache_Core) {                            require_once 'Zend/Date/Exception.php';                            throw new Zend_Date_Exception("Instance of Zend_Cache expected");                        }                        parent::$_cache = $value;                        Zend_Locale_Data::setCache($value);                        break;                    case 'timesync' :                        if (!$value instanceof Zend_TimeSync_Protocol) {                            require_once 'Zend/Date/Exception.php';                            throw new Zend_Date_Exception("Instance of Zend_TimeSync expected");                        }                        $date = $value->getInfo();                        parent::$_defaultOffset = $date['offset'];                        break;                }                self::$_Options[$name] = $value;            }            else {                require_once 'Zend/Date/Exception.php';                throw new Zend_Date_Exception("Unknown option: $name = $value");            }        }    }    /**     * Returns this object's internal UNIX timestamp (equivalent to Zend_Date::TIMESTAMP).     * If the timestamp is too large for integers, then the return value will be a string.     * This function does not return the timestamp as an object.     * Use clone() or copyPart() instead.     *     * @return integer|string  UNIX timestamp     */    public function getTimestamp()    {        return $this->getUnixTimestamp();    }    /**     * Returns the calculated timestamp     * HINT: timestamps are always GMT     *     * @param  string                          $calc    Type of calculation to make     * @param  string|integer|array|Zend_Date  $stamp   Timestamp to calculate, when null the actual timestamp is calculated     * @return Zend_Date|integer     * @throws Zend_Date_Exception     */    private function _timestamp($calc, $stamp)    {        if ($stamp instanceof Zend_Date) {            // extract timestamp from object            $stamp = $stamp->get(Zend_Date::TIMESTAMP, true);        }        if (is_array($stamp)) {            if (array_key_exists('timestamp', $stamp)) {                $stamp = $stamp['timestamp'];            } else {                require_once 'Zend/Date/Exception.php';                throw new Zend_Date_Exception('no timestamp given in array');            }        }        if ($calc === 'set') {            $return = $this->setUnixTimestamp($stamp);        } else {            $return = $this->_calcdetail($calc, $stamp, Zend_Date::TIMESTAMP, null);        }        if ($calc != 'cmp') {            return $this;        }        return $return;    }    /**     * Sets a new timestamp     *     * @param  integer|string|array|Zend_Date  $timestamp  Timestamp to set     * @return Zend_Date

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -