Fix bug in German dates like "1 November 1921"
This commit is contained in:
@ -428,6 +428,10 @@ final class NodaTimeSplitter {
|
||||
if (strlen($datum) <= 9) $use_day = false;
|
||||
else $use_day = true;
|
||||
|
||||
if (self::is_numeric((string)\substr($datum, -4))) $year = \substr($datum, -4);
|
||||
// Further code requires a year to be present, skip if none is set
|
||||
if (empty($year)) return [];
|
||||
|
||||
foreach (self::MONTH_NAMES_ENGLISH as $monthVal => $monthValidNames) {
|
||||
if (self::stri_occurs($datum, $monthValidNames)) {
|
||||
if (!empty($monat)) break;
|
||||
@ -444,10 +448,12 @@ final class NodaTimeSplitter {
|
||||
|
||||
if (empty($monat) and self::is_numeric((string)\substr($datum, 3, 2))) $monat = \substr($datum, 3, 2);
|
||||
|
||||
if (self::is_numeric((string)\substr($datum, 0, 2))) $day = \substr($datum, 0, 2);
|
||||
else if (\substr($datum, 1, 1) === "." and self::is_numeric((string)\substr($datum, 0, 1))) $day = "0" . \substr($datum, 0, 1);
|
||||
|
||||
if (self::is_numeric((string)\substr($datum, -4))) $year = \substr($datum, -4);
|
||||
if (self::is_numeric((string)\substr($datum, 0, 2))) {
|
||||
$day = \substr($datum, 0, 2);
|
||||
}
|
||||
else if (\in_array(\substr($datum, 1, 1), [".", " "]) && self::is_numeric((string)\substr($datum, 0, 1))) {
|
||||
$day = "0" . \substr($datum, 0, 1);
|
||||
}
|
||||
|
||||
if (!empty($year) and !empty($monat) and !empty($day) and $use_day) {
|
||||
return [$year, $year, $monat, $day, '+', ""];
|
||||
@ -493,8 +499,19 @@ final class NodaTimeSplitter {
|
||||
return [];
|
||||
}
|
||||
|
||||
//
|
||||
// Rest: Only those entries, where there are spelled out months
|
||||
//
|
||||
if (strlen($datum) <= 9) return [];
|
||||
|
||||
// The year is only parse-able if it is a four digit year at the start
|
||||
if (self::is_numeric((string)\substr($datum, 0, 4))) {
|
||||
$year = \substr($datum, 0, 4);
|
||||
}
|
||||
|
||||
// Further code requires a year to be present, skip if none is set
|
||||
if (empty($year)) return [];
|
||||
|
||||
foreach (self::MONTH_NAMES_HUNGARIAN as $monthVal => $monthValidNames) {
|
||||
if (self::stri_occurs($datum, $monthValidNames)) {
|
||||
if (!empty($monat)) return [];
|
||||
@ -511,14 +528,14 @@ final class NodaTimeSplitter {
|
||||
if (empty($day)) $day = self::validateDateSubstr($datum, -5, 2);
|
||||
if (empty($day)) $day = self::validateDateSubstr($datum, -6, 2);
|
||||
|
||||
if (\substr($datum, -2, 1) === " " and self::is_numeric((string)\substr($datum, -1, 1))) {
|
||||
$day = "0" . \substr($datum, -1, 1);
|
||||
if (empty($day)) {
|
||||
if (\substr($datum, -2, 1) === " " and self::is_numeric((string)\substr($datum, -1, 1))) {
|
||||
$day = "0" . \substr($datum, -1, 1);
|
||||
}
|
||||
else if (\substr($datum, -3, 1) === " " and self::is_numeric((string)\substr($datum, -2, 1))) {
|
||||
$day = "0" . \substr($datum, -2, 1);
|
||||
}
|
||||
}
|
||||
else if (empty($day) and \substr($datum, -3, 1) === " " and self::is_numeric((string)\substr($datum, -2, 1))) {
|
||||
$day = "0" . \substr($datum, -2, 1);
|
||||
}
|
||||
|
||||
if (self::is_numeric((string)\substr($datum, 0, 4))) $year = \substr($datum, 0, 4);
|
||||
|
||||
if (!empty($year) and !empty($monat) and !empty($day)) {
|
||||
return [$year, $year, $monat, $day, '+', ""];
|
||||
|
Reference in New Issue
Block a user