- Issue created by @erwangel
DateObject doesn't return the same result between DATE_FORMAT_UNIX and DATE_FORMAT_DATETIME when year is in 3 digits.
$date_x = "823-03-06 11:45:05";
dpm($date_x, 'date_x');
$timestamp_0 = strtotime($date_x);
dpm($timestamp_0,'timestamp_0');
$date_object_unix= new DateObject($timestamp_0, 'Europe/Paris', DATE_FORMAT_UNIX);
dpm($date_object_unix, 'date_object_unix');
$date_formated_unix = date_format($date_object_unix, 'Y-m-d H:i:s');
dpm($date_formated_unix, 'date_formated_unix');
$date_object_datetime = new DateObject($date_x, 'Europe/Paris', DATE_FORMAT_DATETIME);
dpm($date_object_datetime , 'date_object_datetime');
$date_formated_datetime = date_format($date_object_datetime, 'Y-m-d H:i:s');
dpm($date_formated_datetime, 'date_formated_datetime ');
With $date_x = 0823 (year in 4 digits)
timestamp = -36190239856;
date_object_unix->originalTime = -36190239856 ; $date_object_unix->errors = ''; $date_formated_unix = 0823-03-06 11:45:05 => GOOD
date_object_datetime->originalTime = 0823-03-06 11:45:05; $date_object->errors = 2; $date_formated_datetime = 0823-03-06 11:45:05 => GOOD
With $date_x = 823-03-06 11:45:05 (year in tree digits)
timestamp = -36190239856;
date_object_unix->originalTime = -36190239856 ; $date_object_unix->errors = ''; $date_formated_unix = 0823-03-06 11:45:05 => GOOD
date_object_datetime->originalTime = 823-03-06 11:45:05; $date_object->errors = 2; $date_formated_datetime = 2023-06-19 13:56:31 => FALSE
With $date_x = -823-03-06 11:45:05 (negative year)
timestamp = '';
$date_object_unix->originalTime = '' ; $date_object_unix->errors = ''; $date_formated_unix = 2023-06-19 13:26 (current date and time) => FALSE
date_object_datetime->originalTime = -823-03-06 11:45:05; $date_object->errors = 2; $date_formated_datetime = 2023-06-19 13:26 (current date and time) => FALSE
Temporary solution: work directly with php DateTime() instead of drupal DateObject()
Active
2.14
Code