@@ -120,6 +120,16 @@ class Zend_Date extends Zend_Date_DateObject
120
120
const RSS = 'SSS ' ;
121
121
const W3C = 'WWW ' ;
122
122
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
+
123
133
/**
124
134
* Generates the standard date object, could be a unix timestamp, localized date,
125
135
* string, integer, array and so on. Also parts of dates or time are supported
@@ -4963,4 +4973,45 @@ protected static function _getLocalizedToken($token, $locale)
4963
4973
4964
4974
return $ token ;
4965
4975
}
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
+ }
4966
5017
}
0 commit comments