$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);
$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;
$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';