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

📄 span.php

📁 太烦了
💻 PHP
📖 第 1 页 / 共 3 页
字号:
                    case 'r':
                        $hour =
                            ($this->hour + 1) > 12 ?
                            $this->hour - 12 :
                            $this->hour;
                        $output .= sprintf(
                            '%02d:%02d:%02d %s',
                            $hour==0 ?  12 : $hour,
                            $this->minute,
                            $this->second,
                            $this->hour >= 12 ? 'pm' : 'am'
                        );
                        break;
                    case 'R':
                        $output .= sprintf(
                            '%02d:%02d', $this->hour, $this->minute
                        );
                        break;
                    case 's':
                        $output .= $this->second;
                        break;
                    case 'S':
                        $output .= sprintf('%02d', $this->second);
                        break;
                    case 't':
                        $output .= "\t";
                        break;
                    case 'T':
                        $output .= sprintf(
                            '%02d:%02d:%02d',
                            $this->hour, $this->minute, $this->second
                        );
                        break;
                    case '%':
                        $output .= "%";
                        break;
                    default:
                        $output .= $char . $nextchar;
                }
            } else {
                $output .= $char;
            }
        }
        return $output;
    }

    /**
     * Convert time span to seconds.
     *
     * @return int Time span as an integer number of seconds.
     *
     * @access public
     */
    function toSeconds()
    {
        return $this->day * 86400 + $this->hour * 3600 +
            $this->minute * 60 + $this->second;
    }

    /**
     * Convert time span to minutes.
     *
     * @return float Time span as a decimal number of minutes.
     *
     * @access public
     */
    function toMinutes()
    {
        return $this->day * 1440 + $this->hour * 60 + $this->minute +
            $this->second / 60;
    }

    /**
     * Convert time span to hours.
     *
     * @return float Time span as a decimal number of hours.
     *
     * @access public
     */
    function toHours()
    {
        return $this->day * 24 + $this->hour + $this->minute / 60 +
            $this->second / 3600;
    }

    /**
     * Convert time span to days.
     *
     * @return float Time span as a decimal number of days.
     *
     * @access public
     */
    function toDays()
    {
        return $this->day + $this->hour / 24 + $this->minute / 1440 +
            $this->second / 86400;
    }

    /**
     * Adds a time span.
     *
     * @param  object Date_Span $time Time span to add.
     *
     * @access public
     */
    function add($time)
    {
        return $this->setFromSeconds(
            $this->toSeconds() + $time->toSeconds()
        );
    }

    /**
     * Subtracts a time span.
     *
     * Subtracts a time span. If the time span to subtract is larger
     * than the original, the result is zero (there's no sense in
     * negative time spans).
     *
     * @param  object Date_Span $time Time span to subtract.
     *
     * @access public
     */
    function subtract($time)
    {
        $sub = $this->toSeconds() - $time->toSeconds();
        if ($sub < 0) {
            $this->setFromSeconds(0);
        } else {
            $this->setFromSeconds($sub);
        }
    }

    /**
     * Tells if time span is equal to $time.
     *
     * @param  object Date_Span $time Time span to compare to.
     *
     * @return bool   True if the time spans are equal.
     *
     * @access public
     */
    function equal($time)
    {
        return $this->toSeconds() == $time->toSeconds();
    }

    /**
     * Tells if this time span is greater or equal than $time.
     *
     * @param  object Date_Span $time Time span to compare to.
     *
     * @return bool   True if this time span is greater or equal than $time.
     *
     * @access public
     */
    function greaterEqual($time)
    {
        return $this->toSeconds() >= $time->toSeconds();
    }

    /**
     * Tells if this time span is lower or equal than $time.
     *
     * @param  object Date_Span $time Time span to compare to.
     *
     * @return bool   True if this time span is lower or equal than $time.
     *
     * @access public
     */
    function lowerEqual($time)
    {
        return $this->toSeconds() <= $time->toSeconds();
    }

    /**
     * Tells if this time span is greater than $time.
     *
     * @param  object Date_Span $time Time span to compare to.
     *
     * @return bool   True if this time span is greater than $time.
     *
     * @access public
     */
    function greater($time)
    {
        return $this->toSeconds() > $time->toSeconds();
    }

    /**
     * Tells if this time span is lower than $time.
     *
     * @param  object Date_Span $time Time span to compare to.
     *
     * @return bool   True if this time span is lower than $time.
     *
     * @access public
     */
    function lower($time)
    {
        return $this->toSeconds() < $time->toSeconds();
    }

    /**
     * Compares two time spans.
     *
     * Compares two time spans. Suitable for use in sorting functions.
     *
     * @param  object Date_Span $time1 The first time span.
     * @param  object Date_Span $time2 The second time span.
     *
     * @return int    0 if the time spans are equal, -1 if time1 is lower
     *                than time2, 1 if time1 is greater than time2.
     *
     * @static
     * @access public
     */
    function compare($time1, $time2)
    {
        if ($time1->equal($time2)) {
            return 0;
        } elseif ($time1->lower($time2)) {
            return -1;
        } else {
            return 1;
        }
    }

    /**
     * Tells if the time span is empty (zero length).
     *
     * @return bool True is it's empty.
     */
    function isEmpty()
    {
        return !$this->day && !$this->hour && !$this->minute && !$this->second;
    }

    /**
     * Set the default input format.
     *
     * @param  mixed $format New default input format.
     *
     * @return mixed Previous default input format.
     *
     * @static
     */
    function setDefaultInputFormat($format)
    {
        $old = $GLOBALS['_DATE_SPAN_INPUT_FORMAT'];
        $GLOBALS['_DATE_SPAN_INPUT_FORMAT'] = $format;
        return $old;
    }

    /**
     * Get the default input format.
     *
     * @return mixed Default input format.
     *
     * @static
     */
    function getDefaultInputFormat()
    {
        return $GLOBALS['_DATE_SPAN_INPUT_FORMAT'];
    }

    /**
     * Set the default format.
     *
     * @param  mixed $format New default format.
     *
     * @return mixed Previous default format.
     *
     * @static
     */
    function setDefaultFormat($format)
    {
        $old = $GLOBALS['_DATE_SPAN_FORMAT'];
        $GLOBALS['_DATE_SPAN_FORMAT'] = $format;
        return $old;
    }

    /**
     * Get the default format.
     *
     * @return mixed Default format.
     *
     * @static
     */
    function getDefaultFormat()
    {
        return $GLOBALS['_DATE_SPAN_FORMAT'];
    }

    /**
     * Returns a copy of the object (workarround for PHP5 forward compatibility).
     *
     * @return object Date_Span Copy of the object.
     */
    function __clone() {
        $c = get_class($this);
        $s = new $c;
        $s->day    = $this->day;
        $s->hour   = $this->hour;
        $s->minute = $this->minute;
        $s->second = $this->second;
        return $s;
    }
}

?>

⌨️ 快捷键说明

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