/** * Check if the given date fits the given format * * @param string $value Date to check * @return boolean False when date does not fit the format */ private function _checkFormat($value) { try { $parsed = \Zend\Locale\Format::getDate($value, array('date_format' => $this->_format, 'format_type' => 'iso', 'fix_date' => false)); if (isset($parsed['year']) and (strpos(strtoupper($this->_format), 'YY') !== false and strpos(strtoupper($this->_format), 'YYYY') === false)) { $parsed['year'] = ZendDate\Date::getFullYear($parsed['year']); } } catch (\Exception $e) { // Date can not be parsed return false; } if ((strpos($this->_format, 'Y') !== false or strpos($this->_format, 'y') !== false) and !isset($parsed['year'])) { // Year expected but not found return false; } if (strpos($this->_format, 'M') !== false and !isset($parsed['month'])) { // Month expected but not found return false; } if (strpos($this->_format, 'd') !== false and !isset($parsed['day'])) { // Day expected but not found return false; } if ((strpos($this->_format, 'H') !== false or strpos($this->_format, 'h') !== false) and !isset($parsed['hour'])) { // Hour expected but not found return false; } if (strpos($this->_format, 'm') !== false and !isset($parsed['minute'])) { // Minute expected but not found return false; } if (strpos($this->_format, 's') !== false and !isset($parsed['second'])) { // Second expected but not found return false; } // Date fits the format return true; }
public function testGetFullYear() { $this->assertSame(1970, Date::getFullYear(70)); $this->assertSame(1999, Date::getFullYear(99)); $this->assertSame(2000, Date::getFullYear(0)); $this->assertSame(2037, Date::getFullYear(37)); $this->assertSame(2069, Date::getFullYear(69)); $this->assertSame(-4, Date::getFullYear(-4)); $this->assertSame(100, Date::getFullYear(100)); }