Skip to content

Commit

Permalink
Merge pull request #2 from msavich/master
Browse files Browse the repository at this point in the history
Added custom fixes
  • Loading branch information
vpelipenko committed Dec 12, 2014
2 parents c22ff60 + d4f39c8 commit 956e87d
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions library/Zend/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ class Zend_Date extends Zend_Date_DateObject
const RSS = 'SSS';
const W3C = 'WWW';

/**
* Minimum allowed year value
*/
const YEAR_MIN_VALUE = -10000;

/**
* Maximum allowed year value
*/
const YEAR_MAX_VALUE = 10000;

/**
* Generates the standard date object, could be a unix timestamp, localized date,
* string, integer, array and so on. Also parts of dates or time are supported
Expand Down Expand Up @@ -4963,4 +4973,45 @@ protected static function _getLocalizedToken($token, $locale)

return $token;
}

/**
* 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);
}
}

0 comments on commit 956e87d

Please sign in to comment.