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

📄 date.php

📁 Bug tracker, and reporter.
💻 PHP
📖 第 1 页 / 共 5 页
字号:
     * @return integer|string|Zend_Date  new timestamp or Zend_Date depending on calculation     */    private function _assign($calc, $date, $comp = 0, $dst = false)    {        switch ($calc) {            case 'set' :                if (!empty($comp)) {                    $this->setUnixTimestamp(call_user_func(Zend_Locale_Math::$sub, $this->getUnixTimestamp(), $comp));                }                $this->setUnixTimestamp(call_user_func(Zend_Locale_Math::$add, $this->getUnixTimestamp(), $date));                $value = $this->getUnixTimestamp();                break;            case 'add' :                $this->setUnixTimestamp(call_user_func(Zend_Locale_Math::$add, $this->getUnixTimestamp(), $date));                $value = $this->getUnixTimestamp();                break;            case 'sub' :                $this->setUnixTimestamp(call_user_func(Zend_Locale_Math::$sub, $this->getUnixTimestamp(), $date));                $value = $this->getUnixTimestamp();                break;            default :                // cmp - compare                return call_user_func(Zend_Locale_Math::$comp, $comp, $date);                break;        }        // dst-correction if 'fix_dst' = true and dst !== false but only for non UTC and non GMT        if ((self::$_Options['fix_dst'] === true) and ($dst !== false) and ($this->_dst === true)) {            $hour = $this->get(Zend_Date::HOUR);            if ($hour != $dst) {                if (($dst == ($hour + 1)) or ($dst == ($hour - 23))) {                    $value += 3600;                } else if (($dst == ($hour - 1)) or ($dst == ($hour + 23))) {                    $value -= 3600;                }                $this->setUnixTimestamp($value);            }        }        return $this->getUnixTimestamp();    }    /**     * Calculates the date or object     *     * @param  string                          $calc    Calculation to make, one of: 'add'|'sub'|'cmp'|'copy'|'set'     * @param  string|integer|array|Zend_Date  $date    Date or datepart to calculate with     * @param  string                          $part    Part of the date to calculate, if null the timestamp is used     * @param  string|Zend_Locale              $locale  Locale for parsing input     * @return integer|string|Zend_Date        new timestamp     * @throws Zend_Date_Exception     */    private function _calculate($calc, $date, $part, $locale)    {        if (is_null($date)) {            require_once 'Zend/Date/Exception.php';            throw new Zend_Date_Exception('parameter $date must be set, null is not allowed');        }        if (Zend_Locale::isLocale($part)) {            $locale = $part;            $part = null;        }        if ($locale === null) {            $locale = $this->getLocale();        }        if ($locale instanceof Zend_Locale) {            $locale = $locale->toString();        }        // create date parts        $year   = $this->get(Zend_Date::YEAR);        $month  = $this->get(Zend_Date::MONTH_SHORT);        $day    = $this->get(Zend_Date::DAY_SHORT);        $hour   = $this->get(Zend_Date::HOUR_SHORT);        $minute = $this->get(Zend_Date::MINUTE_SHORT);        $second = $this->get(Zend_Date::SECOND_SHORT);        // if object extract value        if ($date instanceof Zend_Date) {            $date = $date->get($part, $locale);        }        if (is_array($date)) {            if (!empty($part)) {                switch($part) {                    // Fall through                    case Zend_Date::DAY:                    case Zend_Date::DAY_SHORT:                        if (array_key_exists('day', $date)) {                            $date = $date['day'];                        }                        break;                    // Fall through                    case Zend_Date::WEEKDAY_SHORT:                    case Zend_Date::WEEKDAY:                    case Zend_Date::WEEKDAY_8601:                    case Zend_Date::WEEKDAY_DIGIT:                    case Zend_Date::WEEKDAY_NARROW:                    case Zend_Date::WEEKDAY_NAME:                        if (array_key_exists('weekday', $date)) {                            $date = $date['weekday'];                            $part = Zend_Date::WEEKDAY_DIGIT;                        }                        break;                    case Zend_Date::DAY_OF_YEAR:                        if (array_key_exists('day_of_year', $date)) {                            $date = $date['day_of_year'];                        }                        break;                    // Fall through                    case Zend_Date::MONTH:                    case Zend_Date::MONTH_SHORT:                    case Zend_Date::MONTH_NAME:                    case Zend_Date::MONTH_NAME_SHORT:                    case Zend_Date::MONTH_NAME_NARROW:                        if (array_key_exists('month', $date)) {                            $date = $date['month'];                        }                        break;                    // Fall through                    case Zend_Date::YEAR:                    case Zend_Date::YEAR_SHORT:                    case Zend_Date::YEAR_8601:                    case Zend_Date::YEAR_SHORT_8601:                        if (array_key_exists('year', $date)) {                            $date = $date['year'];                        }                        break;                    // Fall through                    case Zend_Date::HOUR:                    case Zend_Date::HOUR_AM:                    case Zend_Date::HOUR_SHORT:                    case Zend_Date::HOUR_SHORT_AM:                        if (array_key_exists('hour', $date)) {                            $date = $date['hour'];                        }                        break;                    // Fall through                    case Zend_Date::MINUTE:                    case Zend_Date::MINUTE_SHORT:                        if (array_key_exists('minute', $date)) {                            $date = $date['minute'];                        }                        break;                    // Fall through                    case Zend_Date::SECOND:                    case Zend_Date::SECOND_SHORT:                        if (array_key_exists('second', $date)) {                            $date = $date['second'];                        }                        break;                    // Fall through                    case Zend_Date::TIMEZONE:                    case Zend_Date::TIMEZONE_NAME:                        if (array_key_exists('timezone', $date)) {                            $date = $date['timezone'];                        }                        break;                    case Zend_Date::TIMESTAMP:                        if (array_key_exists('timestamp', $date)) {                            $date = $date['timestamp'];                        }                        break;                    case Zend_Date::WEEK:                        if (array_key_exists('week', $date)) {                            $date = $date['week'];                        }                        break;                    case Zend_Date::TIMEZONE_SECS:                        if (array_key_exists('gmtsecs', $date)) {                            $date = $date['gmtsecs'];                        }                        break;                    default:                        require_once 'Zend/Date/Exception.php';                        throw new Zend_Date_Exception("datepart for part ($part) not found in array");                        break;                }            } else {                $hours = 0;                if (array_key_exists("hour", $date)) {                    $hours = $date['hour'];                }                $minutes = 0;                if (array_key_exists('minute', $date)) {                    $minutes = $date['minute'];                }                $seconds = 0;                if (array_key_exists('second', $date)) {                    $seconds = $date['second'];                }                $months = 0;                if (array_key_exists('month', $date)) {                    $months = $date['month'];                }                $days = 0;                if (array_key_exists('day', $date)) {                    $days = $date['day'];                }                $years = 0;                if (array_key_exists('year', $date)) {                    $years = $date['year'];                }                return $this->_assign($calc, $this->mktime($hours, $minutes, $seconds, $months, $days, $years, true),                                             $this->mktime($hour,  $minute,  $second,  $month,  $day,  $year,  true), $hour);            }        }        // $date as object, part of foreign date as own date        switch($part) {            // day formats            case Zend_Date::DAY :                if (is_numeric($date)) {                    return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + intval($date), 1970, true),                                                 $this->mktime(0, 0, 0, 1, 1 + intval($day),  1970, true), $hour);                }                require_once 'Zend/Date/Exception.php';                throw new Zend_Date_Exception("invalid date ($date) operand, day expected", $date);                break;            case Zend_Date::WEEKDAY_SHORT :                $daylist = Zend_Locale_Data::getList($locale, 'day');                $weekday = (int) $this->get(Zend_Date::WEEKDAY_DIGIT, $locale);                $cnt = 0;                foreach ($daylist as $key => $value) {                    if (strtoupper(substr($value, 0, 3)) == strtoupper($date)) {                         $found = $cnt;                        break;                    }                    ++$cnt;                }                // Weekday found                if ($cnt < 7) {                    return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + $found,   1970, true),                                                 $this->mktime(0, 0, 0, 1, 1 + $weekday, 1970, true), $hour);                }                // Weekday not found                require_once 'Zend/Date/Exception.php';                throw new Zend_Date_Exception("invalid date ($date) operand, weekday expected", $date);                break;            case Zend_Date::DAY_SHORT :                if (is_numeric($date)) {                    return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + intval($date), 1970, true),                                                 $this->mktime(0, 0, 0, 1, 1 + intval($day),  1970, true), $hour);                }                require_once 'Zend/Date/Exception.php';                throw new Zend_Date_Exception("invalid date ($date) operand, day expected", $date);                break;            case Zend_Date::WEEKDAY :                $daylist = Zend_Locale_Data::getList($locale, 'day');                $weekday = (int) $this->get(Zend_Date::WEEKDAY_DIGIT, $locale);                $cnt = 0;                foreach ($daylist as $key => $value) {                    if (strtoupper($value) == strtoupper($date)) {                        $found = $cnt;                        break;                    }                    ++$cnt;                }                // Weekday found                if ($cnt < 7) {                    return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + $found,   1970, true),                                                 $this->mktime(0, 0, 0, 1, 1 + $weekday, 1970, true), $hour);                }                // Weekday not found                require_once 'Zend/Date/Exception.php';                throw new Zend_Date_Exception("invalid date ($date) operand, weekday expected", $date);                break;            case Zend_Date::WEEKDAY_8601 :                $weekday = (int) $this->get(Zend_Date::WEEKDAY_8601, $locale);                if ((intval($date) > 0) and (intval($date) < 8)) {                    return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + intval($date), 1970, true),                                                 $this->mktime(0, 0, 0, 1, 1 + $weekday,      1970, true), $hour);                }                // Weekday not found                require_once 'Zend/Date/Exception.php';                throw new Zend_Date_Exception("invalid date ($date) operand, weekday expected", $date);                break;            case Zend_Date::DAY_SUFFIX :                require_once 'Zend/Date/Exception.php';                throw new Zend_Date_Exception('day suffix not supported', $date);                break;            case Zend_Date::WEEKDAY_DIGIT :                $weekday = (int) $this->get(Zend_Date::WEEKDAY_DIGIT, $locale);                if (is_numeric($date) and (intval($date) >= 0) and (intval($date) < 7)) {                    return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + $date,    1970, true),                                                 $this->mktime(0, 0, 0, 1, 1 + $weekday, 1970, true), $hour);                }                // Weekday not found                require_once 'Zend/Date/Exception.php';                throw new Zend_Date_Exception("invalid date ($date) operand, weekday expected", $date);                break;            case Zend_Date::DAY_OF_YEAR :                if (is_numeric($date)) {                    return $this->_assign($calc, $this->mktime(0, 0, 0, 1,      1 + $date, 1970, true),                                                 $this->mktime(0, 0, 0, $month, 1 + $day,  1970, true), $hour);                }                require_once 'Zend/Date/Exception.php';                throw new Zend_Date_Exception("invalid date ($date) operand, day expected", $date);                break;            case Zend_Date::WEEKDAY_NARROW :                $daylist = Zend_Locale_Data::getList($locale, 'day', array('gregorian', 'format', 'abbreviated'));                $weekday = (int) $this->get(Zend_Date::WEEKDAY_DIGIT, $locale);                $cnt = 0;                foreach ($daylist as $key => $value) {                    if (strtoupper(substr($value, 0, 1)) == strtoupper($date)) {                        $found = $cnt;                        break;                    }                    ++$cnt;                }                // Weekday found                if ($cnt < 7) {                    return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + $found,   1970, true),                                                 $this->mktime(0, 0, 0, 1, 1 + $weekday, 1970, true), $hour);                }                // Weekday not found                require_once 'Zend/Date/Exception.php';                throw new Zend_Date_Exception("invalid date ($date) operand, weekday expecte

⌨️ 快捷键说明

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