return $this->copyPart(self::HOUR, $locale); } /** * Sets a new hour * The hour is always a number. * Returned is the new date object * Example: 04.May.1993 13:07:25 -> setHour(7); -> 04.May.1993 07:07:25 * * @param string|integer|array|Zend_Date $hour Hour to set * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input * @return Zend_Date new date * @throws Zend_Date_Exception */ public function setHour($hour, $locale = null) { return $this->_calcvalue('set', $hour, 'hour', self::HOUR_SHORT, $locale); } /** * Adds hours to the existing date object. * The hour is always a number. * Returned is the new date object * Example: 04.May.1993 13:07:25 -> addHour(12); -> 05.May.1993 01:07:25 * * @param string|integer|array|Zend_Date $hour Hour to add * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input * @return Zend_Date new date * @throws Zend_Date_Exception */ public function addHour($hour, $locale = null) { return $this->_calcvalue('add', $hour, 'hour', self::HOUR_SHORT, $locale); } /** * Subtracts hours from the existing date object. * The hour is always a number. * Returned is the new date object * Example: 04.May.1993 13:07:25 -> subHour(6); -> 05.May.1993 07:07:25 * * @param string|integer|array|Zend_Date $hour Hour to sub * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input * @return Zend_Date new date * @throws Zend_Date_Exception */ public function subHour($hour, $locale = null) { return $this->_calcvalue('sub', $hour, 'hour', self::HOUR_SHORT, $locale); } /** * Compares the hour with the existing date object. * For example: 10:30:25 -> compareHour(10) -> 0 * Returns if equal, earlier or later * * @param string|integer|array|Zend_Date $hour Hour to compare * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input * @return integer 0 = equal, 1 = later, -1 = earlier * @throws Zend_Date_Exception */ public function compareHour($hour, $locale = null) { return $this->_calcvalue('cmp', $hour, 'hour', self::HOUR_SHORT, $locale); } /** * Returns the minute as new date object * Example: 02.Feb.1986 10:30:25 -> 01.Jan.1970 00:30:00 * * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input * @return Zend_Date */ public function getMinute($locale = null) { return $this->copyPart(self::MINUTE, $locale); } /** * Sets a new minute * The minute is always a number. * Returned is the new date object * Example: 04.May.1993 13:07:25 -> setMinute(29); -> 04.May.1993 13:29:25 * * @param string|integer|array|Zend_Date $minute Minute to set * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input * @return Zend_Date new date * @throws Zend_Date_Exception */ public function setMinute($minute, $locale = null) { return $this->_calcvalue('set', $minute, 'minute', self::MINUTE_SHORT, $locale); } /** * Adds minutes to the existing date object. * The minute is always a number. * Returned is the new date object * Example: 04.May.1993 13:07:25 -> addMinute(65); -> 04.May.1993 13:12:25 * * @param string|integer|array|Zend_Date $minute Minute to add * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input * @return Zend_Date new date * @throws Zend_Date_Exception */ public function addMinute($minute, $locale = null) { return $this->_calcvalue('add', $minute, 'minute', self::MINUTE_SHORT, $locale); } /** * Subtracts minutes from the existing date object. * The minute is always a number. * Returned is the new date object * Example: 04.May.1993 13:07:25 -> subMinute(9); -> 04.May.1993 12:58:25 * * @param string|integer|array|Zend_Date $minute Minute to sub * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input * @return Zend_Date new date * @throws Zend_Date_Exception */ public function subMinute($minute, $locale = null) { return $this->_calcvalue('sub', $minute, 'minute', self::MINUTE_SHORT, $locale); } /** * Compares the minute with the existing date object. * For example: 10:30:25 -> compareMinute(30) -> 0 * Returns if equal, earlier or later * * @param string|integer|array|Zend_Date $minute Hour to compare * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input * @return integer 0 = equal, 1 = later, -1 = earlier * @throws Zend_Date_Exception */ public function compareMinute($minute, $locale = null) { return $this->_calcvalue('cmp', $minute, 'minute', self::MINUTE_SHORT, $locale); } /** * Returns the second as new date object * Example: 02.Feb.1986 10:30:25 -> 01.Jan.1970 00:00:25 * * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input * @return Zend_Date */ public function getSecond($locale = null) { return $this->copyPart(self::SECOND, $locale); } /** * Sets new seconds to the existing date object. * The second is always a number. * Returned is the new date object * Example: 04.May.1993 13:07:25 -> setSecond(100); -> 04.May.1993 13:08:40 * * @param string|integer|array|Zend_Date $second Second to set * @param string|Zend_Locale $locale (Optional) Locale for parsing input * @return Zend_Date new date * @throws Zend_Date_Exception */ public function setSecond($second, $locale = null) { return $this->_calcvalue('set', $second, 'second', self::SECOND_SHORT, $locale); } /** * Adds seconds to the existing date object. * The second is always a number. * Returned is the new date object * Example: 04.May.1993 13:07:25 -> addSecond(65); -> 04.May.1993 13:08:30 * * @param string|integer|array|Zend_Date $second Second to add * @param string|Zend_Locale $locale (Optional) Locale for parsing input * @return Zend_Date new date * @throws Zend_Date_Exception */ public function addSecond($second, $locale = null) { return $this->_calcvalue('add', $second, 'second', self::SECOND_SHORT, $locale); } /** * Subtracts seconds from the existing date object. * The second is always a number. * Returned is the new date object * Example: 04.May.1993 13:07:25 -> subSecond(10); -> 04.May.1993 13:07:15 * * @param string|integer|array|Zend_Date $second Second to sub * @param string|Zend_Locale $locale (Optional) Locale for parsing input * @return Zend_Date new date * @throws Zend_Date_Exception */ public function subSecond($second, $locale = null) { return $this->_calcvalue('sub', $second, 'second', self::SECOND_SHORT, $locale); } /** * Compares the second with the existing date object. * For example: 10:30:25 -> compareSecond(25) -> 0 * Returns if equal, earlier or later * * @param string|integer|array|Zend_Date $second Second to compare * @param string|Zend_Locale $locale (Optional) Locale for parsing input * @return integer 0 = equal, 1 = later, -1 = earlier * @throws Zend_Date_Exception */ public function compareSecond($second, $locale = null) { return $this->_calcvalue('cmp', $second, 'second', self::SECOND_SHORT, $locale); } /** * Returns the precision for fractional seconds * * @return integer */ public function getFractionalPrecision() { return $this->_precision; } /** * Sets a new precision for fractional seconds * * @param integer $precision Precision for the fractional datepart 3 = milliseconds * @throws Zend_Date_Exception * @return void */ public function setFractionalPrecision($precision) { if (!intval($precision) or ($precision < 0) or ($precision > 9)) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("precision ($precision) must be a positive integer less than 10", $precision); } $this->_precision = (int) $precision; } /** * Returns the milliseconds of the date object * * @return integer */ public function getMilliSecond() { return $this->_fractional; } /** * Sets new milliseconds for the date object * Example: setMilliSecond(550, 2) -> equals +5 Sec +50 MilliSec * * @param integer|Zend_Date $milli (Optional) Millisecond to set, when null the actual millisecond is set * @param integer $precision (Optional) Fraction precision of the given milliseconds * @return integer|string */ public function setMilliSecond($milli = null, $precision = null) { if ($milli === null) { list($milli, $time) = explode(" ", microtime()); $milli = intval($milli); $precision = 6; } else if (!is_numeric($milli)) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid milli second ($milli) operand", $milli); } if ($precision === null) { $precision = $this->_precision; } else if (!is_int($precision) || $precision < 1 || $precision > 9) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("precision ($precision) must be a positive integer less than 10", $precision); } $this->_fractional = 0; $this->addMilliSecond($milli, $precision); return $this->_fractional; } /** * Adds milliseconds to the date object * * @param integer|Zend_Date $milli (Optional) Millisecond to add, when null the actual millisecond is added * @param integer $precision (Optional) Fractional precision for the given milliseconds * @return integer|string */ public function addMilliSecond($milli = null, $precision = null) { if ($milli === null) { list($milli, $time) = explode(" ", microtime()); $milli = intval($milli); } else if (!is_numeric($milli)) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid milli second ($milli) operand", $milli); } if ($precision === null) { $precision = $this->_precision; } else if (!is_int($precision) || $precision < 1 || $precision > 9) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("precision ($precision) must be a positive integer less than 10", $precision); } if ($precision != $this->_precision) { if ($precision > $this->_precision) { $diff = $precision - $this->_precision; $milli = (int) ($milli / (10 * $diff)); } else { $diff = $this->_precision - $precision; $milli = (int) ($milli * (10 * $diff)); } } $this->_fractional += $milli; // Add/sub milliseconds + add/sub seconds $max = pow(10, $this->_precision); // Milli includes seconds if ($this->_fractional >= $max) { while ($this->_fractional >= $max) { $this->addSecond(1); $this->_fractional -= $max; } } if ($this->_fractional < 0) { while ($this->_fractional < 0) { $this->subSecond(1); $this->_fractional += $max; } } return $this->_fractional; } /** * Subtracts a millisecond * * @param integer|Zend_Date $milli (Optional) Millisecond to sub, when null the actual millisecond is subtracted * @param integer $precision (Optional) Fractional precision for the given milliseconds * @return integer */ public function subMilliSecond($milli = null, $precision = null) { return $this->addMilliSecond(0 - $milli, $precision); } /** * Compares only the millisecond part, returning the difference * * @param integer|Zend_Date $milli OPTIONAL Millisecond to compare, when null the actual millisecond is compared * @param integer $precision OPTIONAL Fractional precision for the given milliseconds * @return integer */ public function compareMilliSecond($milli = null, $precision = null) { if ($milli === null) { list($milli, $time) = explode(" ", microtime()); $milli = intval($milli); } else if (is_numeric($milli) === false) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("invalid milli second ($milli) operand", $milli); } if ($precision === null) { $precision = $this->_precision; } else if (!is_int($precision) || $precision < 1 || $precision > 9) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("precision ($precision) must be a positive integer less than 10", $precision); } if ($precision === 0) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception('precision is 0'); } if ($precision != $this->_precision) { if ($precision > $this->_precision) { $diff = $precision - $this->_precision; $milli = (int) ($milli / (10 * $diff)); } else { $diff = $this->_precision - $precision; $milli = (int) ($milli * (10 * $diff)); } } $comp = $this->_fractional - $milli; if ($comp < 0) { return -1; } else if ($comp > 0) { return 1; } return 0; } /** * Returns the week as new date object using monday as begining of the week * Example: 12.Jan.2007 -> 08.Jan.1970 00:00:00 * * @param $locale string|Zend_Locale OPTIONAL Locale for parsing input * @return Zend_Date */ public function getWeek($locale = null) { return $this->copyPart(self::WEEK, $locale); } /** * Sets a new week. The week is always a number. The day of week is not changed. * Returned is the new date object * Example: 09.Jan.2007 13:07:25 -> setWeek(1); -> 02.Jan.2007 13:07:25 * * @param string|integer|array|Zend_Date $week Week to set * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input * @return Zend_Date * @throws Zend_Date_Exception */ public function setWeek($week, $locale = null) { return $this->_calcvalue('set', $week, 'week', self::WEEK, $locale); } /** * Adds a week. The week is always a number. The day of week is not changed. * Returned is the new date object * Example: 09.Jan.2007 13:07:25 -> addWeek(1); -> 16.Jan.2007 13:07:25 * * @param string|integer|array|Zend_Date $week Week to add * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input * @return Zend_Date * @throws Zend_Date_Exception */ public function addWeek($week, $locale = null) { return $this->_calcvalue('add', $week, 'week', self::WEEK, $locale); } /** * Subtracts a week. The week is always a number. The day of week is not changed. * Returned is the new date object * Example: 09.Jan.2007 13:07:25 -> subWeek(1); -> 02.Jan.2007 13:07:25 * * @param string|integer|array|Zend_Date $week Week to sub * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input * @return Zend_Date * @throws Zend_Date_Exception */ public function subWeek($week, $locale = null) { return $this->_calcvalue('sub', $week, 'week', self::WEEK, $locale); } /** * Compares only the week part, returning the difference * Returned is the new date object * Returns if equal, earlier or later * Example: 09.Jan.2007 13:07:25 -> compareWeek(2); -> 0 * * @param string|integer|array|Zend_Date $week Week to compare * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input * @return integer 0 = equal, 1 = later, -1 = earlier */ public function compareWeek($week, $locale = null) { return $this->_calcvalue('cmp', $week, 'week', self::WEEK, $locale); } /** * Sets a new standard locale for the date object. * This locale will be used for all functions * Returned is the really set locale. * Example: 'de_XX' will be set to 'de' because 'de_XX' does not exist * 'xx_YY' will be set to 'root' because 'xx' does not exist * * @param string|Zend_Locale $locale (Optional) Locale for parsing input * @throws Zend_Date_Exception When the given locale does not exist * @return Zend_Date Provides fluent interface */ public function setLocale($locale = null) { try { $this->_locale = Zend_Locale::findLocale($locale); } catch (Zend_Locale_Exception $e) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception($e->getMessage()); } return $this; } /** * Returns the actual set locale * * @return string */ public function getLocale() { return $this->_locale; } /** * Checks if the given date is a real date or datepart. * Returns false if a expected datepart is missing or a datepart exceeds its possible border. * But the check will only be done for the expected dateparts which are given by format. * If no format is given the standard dateformat for the actual locale is used. * f.e. 30.February.2007 will return false if format is 'dd.MMMM.YYYY' * * @param string|array|Zend_Date $date Date to parse for correctness * @param string $format (Optional) Format for parsing the date string * @param string|Zend_Locale $locale (Optional) Locale for parsing date parts * @return boolean True when all date parts are correct */ public static function isDate($date, $format = null, $locale = null) { if (!is_string($date) && !is_numeric($date) && !($date instanceof Zend_Date) && !is_array($date)) { return false; } if (($format !== null) and (Zend_Locale::isLocale($format, null, false))) { $locale = $format; $format = null; } $locale = Zend_Locale::findLocale($locale); if ($format === null) { $format = Zend_Locale_Format::getDateFormat($locale); } else if (self::$_options['format_type'] == 'php') { $format = Zend_Locale_Format::convertPhpToIsoFormat($format); } $format = self::_getLocalizedToken($format, $locale); if (!is_array($date)) { try { $parsed = Zend_Locale_Format::getDate($date, array('locale' => $locale, 'date_format' => $format, 'format_type' => 'iso', 'fix_date' => false)); } catch (Zend_Locale_Exception $e) { // Date can not be parsed return false; } } else { $parsed = $date; } if (((strpos($format, 'Y') !== false) or (strpos($format, 'y') !== false)) and (!isset($parsed['year']))) { // Year expected but not found return false; } if ((strpos($format, 'M') !== false) and (!isset($parsed['month']))) { // Month expected but not found return false; } if ((strpos($format, 'd') !== false) and (!isset($parsed['day']))) { // Day expected but not found return false; } if (((strpos($format, 'H') !== false) or (strpos($format, 'h') !== false)) and (!isset($parsed['hour']))) { // Hour expected but not found return false; } if ((strpos($format, 'm') !== false) and (!isset($parsed['minute']))) { // Minute expected but not found return false; } if ((strpos($format, 's') !== false) and (!isset($parsed['second']))) { // Second expected but not found return false; } // Set not given dateparts if (isset($parsed['hour']) === false) { $parsed['hour'] = 12; } if (isset($parsed['minute']) === false) { $parsed['minute'] = 0; } if (isset($parsed['second']) === false) { $parsed['second'] = 0; } if (isset($parsed['month']) === false) { $parsed['month'] = 1; } if (isset($parsed['day']) === false) { $parsed['day'] = 1; } if (isset($parsed['year']) === false) { $parsed['year'] = 1970; } if (self::isYearLeapYear($parsed['year'])) { $parsed['year'] = 1972; } else { $parsed['year'] = 1971; } $date = new self($parsed, null, $locale); $timestamp = $date->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $parsed['month'], $parsed['day'], $parsed['year']); if ($parsed['year'] != $date->date('Y', $timestamp)) { // Given year differs from parsed year return false; } if ($parsed['month'] != $date->date('n', $timestamp)) { // Given month differs from parsed month return false; } if ($parsed['day'] != $date->date('j', $timestamp)) { // Given day differs from parsed day return false; } if ($parsed['hour'] != $date->date('G', $timestamp)) { // Given hour differs from parsed hour return false; } if ($parsed['minute'] != $date->date('i', $timestamp)) { // Given minute differs from parsed minute return false; } if ($parsed['second'] != $date->date('s', $timestamp)) { // Given second differs from parsed second return false; } return true; } /** * Returns the ISO Token for all localized constants * * @param string $token Token to normalize * @param string $locale Locale to search * @return string */ protected static function _getLocalizedToken($token, $locale) { switch($token) { case self::ISO_8601 : return "dd mm yy"; break; case self::RFC_2822 : return "EEE, dd MMM yyyy HH:mm:ss"; break; case self::DATES : return Zend_Locale_Data::getContent($locale, 'date'); break; case self::DATE_FULL : return Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'full')); break; case self::DATE_LONG : return Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'long')); break; case self::DATE_MEDIUM : return Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'medium')); break; case self::DATE_SHORT : return Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'short')); break; case self::TIMES : return Zend_Locale_Data::getContent($locale, 'date'); break; case self::TIME_FULL : return Zend_Locale_Data::getContent($locale, 'time', array('gregorian', 'full')); break; case self::TIME_LONG : return Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'long')); break; case self::TIME_MEDIUM : return Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'medium')); break; case self::TIME_SHORT : return Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'short')); break; case self::DATETIME : return Zend_Locale_Data::getContent($locale, 'datetime'); break; case self::DATETIME_FULL : return Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'full')); break; case self::DATETIME_LONG : return Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'long')); break; case self::DATETIME_MEDIUM : return Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'medium')); break; case self::DATETIME_SHORT : return Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'short')); break; case self::ATOM : case self::RFC_3339 : case self::W3C : return "yyyy-MM-DD HH:mm:ss"; break; case self::COOKIE : case self::RFC_850 : return "EEEE, dd-MM-yyyy HH:mm:ss"; break; case self::RFC_822 : case self::RFC_1036 : case self::RFC_1123 : case self::RSS : return "EEE, dd MM yyyy HH:mm:ss"; break; } return $token; } } Kodo/kodo - Gogs: Go Git Service

5 Commity (f403b7af707d00d9fbfd2c7341efbce2ab6f5f07)

Autor SHA1 Wiadomość Data
  Brightcells 2eba3ed7f9 Add guest login for tourguide 8 lat temu
  Brightcells 5ebf9b60ba have_active_group 8 lat temu
  Brightcells 246a9ff4b8 Change to 'from utils.redis.connect import r' 8 lat temu
  Brightcells ad69866b26 Add tour guide's name and phone in GroupInfo 8 lat temu
  Brightcells f724e0f9c0 Add tour guide apis 8 lat temu