Handle dates outside of strtotime()'s range in date_to_int, int_to_date

Close #9
This commit is contained in:
jrenslin committed 2024-05-05 00:48:04 +02:00
1 parent fb1372d193
commit d4918dd893
2 files changed
+6 -7

No files matched your search

+5 -6
View File
@@ -939,12 +939,11 @@ public static function split_string_array_into_sized_parts(array $input, int $si
*/
public static function date_to_int(string $date):int {
// Edge case: -0000-01-01
if (substr($date, 0, 5) === '-0000') {
return -1 * intval(str_replace("-", "", ltrim($date, "0-")));
}
$isNegative = substr($date, 0, 1) === '-';
$parts = explode('-', $date);
return intval(date("Ymd", self::strtotime($date)));
if ($isNegative === true) return -1 * intval(implode($parts));
else return intval(implode($parts));
}
@@ -973,7 +972,7 @@ public static function int_to_date(int $date_int):string {
$day = substr($dateStr, -2, 2);
$month = substr($dateStr, -4, 2);
$year = substr($dateStr, -8, 4);
$year = substr($dateStr, 0, -4);
return match($isNegative) {
true => '-',