diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 411499f1ae5..9e57b24751a 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -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); diff --git a/mod/data/tests/generator/lib.php b/mod/data/tests/generator/lib.php index b02a97c38d9..4996bc8b8b5 100644 --- a/mod/data/tests/generator/lib.php +++ b/mod/data/tests/generator/lib.php @@ -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; diff --git a/mod/data/tests/generator_test.php b/mod/data/tests/generator_test.php index 113a1147dc1..be201cfba0d 100644 --- a/mod/data/tests/generator_test.php +++ b/mod/data/tests/generator_test.php @@ -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';