MDL_41126 phpunit: Timestamp should be less than 2038
http://php.net/manual/en/datetime.gettimestamp.php#114590 In 32-bit system the unix timestamp will overflow if the date goes beyond year 2038 and this method will return false.
This commit is contained in:
@@ -2053,6 +2053,11 @@ function make_timestamp($year, $month=1, $day=1, $hour=0, $minute=0, $second=0,
|
||||
|
||||
$time = $date->getTimestamp();
|
||||
|
||||
if ($time === false) {
|
||||
throw new coding_exception('getTimestamp() returned false, please ensure you have passed correct values.'.
|
||||
' This can fail if year is more than 2038 and OS is 32 bit windows');
|
||||
}
|
||||
|
||||
// Moodle BC DST stuff.
|
||||
if (!$applydst) {
|
||||
$time += dst_offset_on($time, $timezone);
|
||||
|
||||
@@ -293,12 +293,18 @@ class mod_data_generator extends testing_module_generator {
|
||||
|
||||
$temp = explode('-', $content, 3);
|
||||
|
||||
$values['field_'.$fieldid.'_day'] = $temp[0];
|
||||
$values['field_'.$fieldid.'_month'] = $temp[1];
|
||||
$values['field_'.$fieldid.'_year'] = $temp[2];
|
||||
$values['field_'.$fieldid.'_day'] = (int)trim($temp[0]);
|
||||
$values['field_'.$fieldid.'_month'] = (int)trim($temp[1]);
|
||||
$values['field_'.$fieldid.'_year'] = (int)trim($temp[2]);
|
||||
|
||||
// Year should be less than 2038, so it can be handled by 32 bit windows.
|
||||
if ($values['field_'.$fieldid.'_year'] > 2038) {
|
||||
throw new coding_exception('DateTime::getTimestamp resturns false on 32 bit win for year beyond '.
|
||||
'2038. Please use year less than 2038.');
|
||||
}
|
||||
|
||||
foreach ($values as $fieldname => $value) {
|
||||
$field->update_content($recordid, (string)(int)trim($value), $fieldname);
|
||||
$field->update_content($recordid, $value, $fieldname);
|
||||
}
|
||||
|
||||
continue;
|
||||
|
||||
@@ -181,7 +181,7 @@ class mod_data_generator_testcase extends advanced_testcase {
|
||||
|
||||
$contents = array();
|
||||
$contents[] = array('one', 'two', 'three', 'four');
|
||||
$contents[] = '01-01-2100';
|
||||
$contents[] = '01-01-2037'; // It should be lower than 2038, to avoid failing on 32-bit windows.
|
||||
$contents[] = 'one';
|
||||
$contents[] = array('one', 'two', 'three', 'four');
|
||||
$contents[] = '12345';
|
||||
|
||||
Reference in New Issue
Block a user