Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 956e87d

Browse files
committed
Merge pull request #2 from msavich/master
Added custom fixes
2 parents c22ff60 + d4f39c8 commit 956e87d

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

library/Zend/Date.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ class Zend_Date extends Zend_Date_DateObject
120120
const RSS = 'SSS';
121121
const W3C = 'WWW';
122122

123+
/**
124+
* Minimum allowed year value
125+
*/
126+
const YEAR_MIN_VALUE = -10000;
127+
128+
/**
129+
* Maximum allowed year value
130+
*/
131+
const YEAR_MAX_VALUE = 10000;
132+
123133
/**
124134
* Generates the standard date object, could be a unix timestamp, localized date,
125135
* string, integer, array and so on. Also parts of dates or time are supported
@@ -4963,4 +4973,45 @@ protected static function _getLocalizedToken($token, $locale)
49634973

49644974
return $token;
49654975
}
4976+
4977+
/**
4978+
* Get unix timestamp.
4979+
* Added limitation: $year value must be between -10 000 and 10 000
4980+
* Parent method implementation causes 504 error if it gets too big(small) year value
4981+
*
4982+
* @see Zend_Date_DateObject::mktime
4983+
* @throws Zend_Date_Exception
4984+
* @param $hour
4985+
* @param $minute
4986+
* @param $second
4987+
* @param $month
4988+
* @param $day
4989+
* @param $year
4990+
* @param bool $gmt
4991+
* @return float|int
4992+
*/
4993+
protected function mktime($hour, $minute, $second, $month, $day, $year, $gmt = false)
4994+
{
4995+
$day = intval($day);
4996+
$month = intval($month);
4997+
$year = intval($year);
4998+
4999+
// correct months > 12 and months < 1
5000+
if ($month > 12) {
5001+
$overlap = floor($month / 12);
5002+
$year += $overlap;
5003+
$month -= $overlap * 12;
5004+
} else {
5005+
$overlap = ceil((1 - $month) / 12);
5006+
$year -= $overlap;
5007+
$month += $overlap * 12;
5008+
}
5009+
5010+
if ($year > self::YEAR_MAX_VALUE || $year < self::YEAR_MIN_VALUE) {
5011+
throw new Zend_Date_Exception('Invalid year, it must be between ' . self::YEAR_MIN_VALUE . ' and '
5012+
. self::YEAR_MAX_VALUE);
5013+
}
5014+
5015+
return parent::mktime($hour, $minute, $second, $month, $day, $year, $gmt);
5016+
}
49665017
}

0 commit comments

Comments
 (0)