/**
  * Check a given year for leap year.
  *
  * @param  integer|array|Zend_Date  $year  Year to check
  * @return boolean
  */
 public static function checkLeapYear($year)
 {
     if ($year instanceof Zend_Date) {
         $year = (int) $year->toString(self::YEAR, 'iso');
     }
     if (is_array($year)) {
         if (isset($year['year']) === true) {
             $year = $year['year'];
         } else {
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("no year given in array");
         }
     }
     if (!is_numeric($year)) {
         require_once 'Zend/Date/Exception.php';
         throw new Zend_Date_Exception("year ({$year}) has to be integer for checkLeapYear()", 0, null, $year);
     }
     return (bool) parent::isYearLeapYear($year);
 }
 public function dayOfWeekHelper($y, $m, $d)
 {
     return Zend_Date_DateObject::dayOfWeek($y, $m, $d);
 }
Exemple #3
0
 /**
  * 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') {
                         throw new Exception\InvalidArgumentException("Unknown format type ({$value}) for dates, only 'iso' and 'php' supported");
                         /*, 0, null, $value */
                     }
                     break;
                 case 'fix_dst':
                     if (!is_bool($value)) {
                         throw new Exception\InvalidArgumentException("'fix_dst' has to be boolean");
                         /* , 0, null, $value */
                     }
                     break;
                 case 'extend_month':
                     if (!is_bool($value)) {
                         throw new Exception\InvalidArgumentException("'extend_month' has to be boolean");
                         /* ); */
                     }
                     break;
                 case 'cache':
                     if ($value === null) {
                         parent::$_cache = null;
                     } else {
                         if (!$value instanceof \Zend\Cache\Frontend) {
                             throw new Exception\InvalidArgumentException("Instance of Zend_Cache expected");
                         }
                         parent::$_cache = $value;
                         parent::$_cacheTags = Zend_Date_DateObject::hasCacheTagSupport();
                         Cldr::setCache($value);
                     }
                     break;
                 case 'timesync':
                     if ($value === null) {
                         parent::$_defaultOffset = 0;
                     } else {
                         if (!$value instanceof TimeSync\Protocol) {
                             throw new Exception\InvalidArgumentException("Instance of Zend_TimeSync expected for option timesync");
                         }
                         $date = $value->getInfo();
                         parent::$_defaultOffset = $date['offset'];
                     }
                     break;
             }
             self::$_options[$name] = $value;
         } else {
             throw new Exception\InvalidArgumentException("Unknown option: {$name} = {$value}");
         }
     }
 }
 /**
  * Internal method to check if the given cache supports tags
  *
  * @param Zend_Cache $cache
  */
 protected static function _getTagSupportForCache()
 {
     $backend = self::$_cache->getBackend();
     if ($backend instanceof Zend_Cache_Backend_ExtendedInterface) {
         $cacheOptions = $backend->getCapabilities();
         self::$_cacheTags = $cacheOptions['tags'];
     } else {
         self::$_cacheTags = false;
     }
     return self::$_cacheTags;
 }
Exemple #5
0
 /**
  * Check a given year for leap year.
  *
  * @param  integer|array|Zend_Date  $year  Year to check
  * @return boolean
  */
 public static function checkLeapYear($year)
 {
     if ($year instanceof Zend_Date) {
         $year = (int) $year->get(Zend_Date::YEAR);
     }
     if (is_array($year)) {
         if (array_key_exists('year', $year)) {
             $year = $year['year'];
         } else {
             require_once 'Zend/Date/Exception.php';
             throw new Zend_Date_Exception("no year given in array");
         }
     }
     if (!is_numeric($year)) {
         require_once 'Zend/Date/Exception.php';
         throw new Zend_Date_Exception("year ({$year}) has to be integer for checkLeapYear()", $year);
     }
     return (bool) parent::isYearLeapYear($year);
 }
Exemple #6
0
 /**
  * Check a given year for leap year.
  *
  * @param  integer|Zend_Date  $year  Year to check
  * @return boolean
  */
 public static function checkLeapYear($year)
 {
     if ($year instanceof Zend_Date) {
         $year = (int) $year->get(Zend_Date::YEAR);
     }
     if (!is_numeric($year)) {
         throw new Zend_Date_Exception("year ({$year}) has to be integer for isLeapYear()", $year);
     }
     return (bool) parent::isYearLeapYear($year);
 }
 /**
  * Get unix timestamp.
  * Added limitation: $year value must be between -10 000 and 10 000
  * Parent method implementation causes 504 error if it gets too big(small) year value
  *
  * @see Zend_Date_DateObject::mktime
  * @throws Zend_Date_Exception
  * @param $hour
  * @param $minute
  * @param $second
  * @param $month
  * @param $day
  * @param $year
  * @param bool $gmt
  * @return float|int
  */
 protected function mktime($hour, $minute, $second, $month, $day, $year, $gmt = false)
 {
     $day = intval($day);
     $month = intval($month);
     $year = intval($year);
     // correct months > 12 and months < 1
     if ($month > 12) {
         $overlap = floor($month / 12);
         $year += $overlap;
         $month -= $overlap * 12;
     } else {
         $overlap = ceil((1 - $month) / 12);
         $year -= $overlap;
         $month += $overlap * 12;
     }
     if ($year > self::YEAR_MAX_VALUE || $year < self::YEAR_MIN_VALUE) {
         throw new Zend_Date_Exception('Invalid year, it must be between ' . self::YEAR_MIN_VALUE . ' and ' . self::YEAR_MAX_VALUE);
     }
     return parent::mktime($hour, $minute, $second, $month, $day, $year, $gmt);
 }
 public function testDate()
 {
     $date = new Zend_Date_DateObject(0);
     $this->assertTrue($date->date('U') > 0);
     $this->assertSame($date->date('U', 0), '0');
     $this->assertSame($date->date('U', 0, false), '0');
     $this->assertSame($date->date('U', 0, true), '0');
     $this->assertSame($date->date('U', 6900000000), '6900003600');
     $this->assertSame($date->date('U', -7000000000), '-6999996400');
     $this->assertSame($date->date('d', -7000000000), '06');
     $this->assertSame($date->date('D', -7000000000), 'Wed');
     $this->assertSame($date->date('j', -7000000000), '6');
     $this->assertSame($date->date('l', -7000000000), 'Wednesday');
     $this->assertSame($date->date('N', -7000000000), '3');
     $this->assertSame($date->date('S', -7000000000), 'th');
     $this->assertSame($date->date('w', -7000000000), '3');
     $this->assertSame($date->date('z', -7000000000), '65');
     $this->assertSame($date->date('W', -7000000000), '10');
     $this->assertSame($date->date('F', -7000000000), 'March');
     $this->assertSame($date->date('m', -7000000000), '03');
     $this->assertSame($date->date('M', -7000000000), 'Mar');
     $this->assertSame($date->date('n', -7000000000), '3');
     $this->assertSame($date->date('t', -7000000000), '31');
     $this->assertSame($date->date('T', -7000000000), 'CET');
     $this->assertSame($date->date('L', -7000000000), '1');
     $this->assertSame($date->date('o', -7000000000), '1748');
     $this->assertSame($date->date('Y', -7000000000), '1748');
     $this->assertSame($date->date('y', -7000000000), '48');
     $this->assertSame($date->date('a', -7000000000), 'pm');
     $this->assertSame($date->date('A', -7000000000), 'PM');
     $this->assertSame($date->date('B', -7000000000), '523');
     $this->assertSame($date->date('g', -7000000000), '12');
     $this->assertSame($date->date('G', -7000000000), '12');
     $this->assertSame($date->date('h', -7000000000), '12');
     $this->assertSame($date->date('H', -7000000000), '12');
     $this->assertSame($date->date('i', -7000000000), '33');
     $this->assertSame($date->date('s', -7000000000), '20');
     $this->assertSame($date->date('e', -7000000000), 'Europe/Paris');
     $this->assertSame($date->date('I', -7000000000), '0');
     $this->assertSame($date->date('O', -7000000000), '+0100');
     $this->assertSame($date->date('P', -7000000000), '+01:00');
     $this->assertSame($date->date('T', -7000000000), 'CET');
     $this->assertSame($date->date('Z', -7000000000), '3600');
     $this->assertSame($date->date('c', -7000000000), '1748-3-06T12:33:20+01:00');
     $this->assertSame($date->date('r', -7000000000), 'Wed, 06 Mar 1748 12:33:20 +0100');
     $this->assertSame($date->date('U', -7000000000), '-6999996400');
     $this->assertSame($date->date('\\H', -7000000000), 'H');
     $this->assertSame($date->date('.', -7000000000), '.');
     $this->assertSame($date->date('H:m:s', -7000000000), '12:03:20');
     $this->assertSame($date->date('d-M-Y', -7000000000), '06-Mar-1748');
     $this->assertSame($date->date('U', 6900000000, true), '6900000000');
     $this->assertSame($date->date('B', 6900000000, true), '152');
     $this->assertSame($date->date('g', 6899993000, true), '12');
     $this->assertSame($date->date('g', 6899997000, true), '1');
     $this->assertSame($date->date('g', 6900039200, true), '1');
     $this->assertSame($date->date('h', 6899993000, true), '12');
     $this->assertSame($date->date('h', 6899997000, true), '01');
     $this->assertSame($date->date('h', 6900040200, true), '01');
     $this->assertSame($date->date('e', -7000000000, true), 'UTC');
     $this->assertSame($date->date('I', -7000000000, true), '0');
     $this->assertSame($date->date('T', -7000000000, true), 'GMT');
     $this->assertSame($date->date('N', 6899740800, true), '6');
     $this->assertSame($date->date('S', 6900518000, true), 'st');
     $this->assertSame($date->date('S', 6900604800, true), 'nd');
     $this->assertSame($date->date('S', 6900691200, true), 'rd');
     $this->assertSame($date->date('N', 6900432000, true), '7');
 }