Correctly handle multibype hyphens in XXXX-XXXX

This commit is contained in:
Joshua Ramon Enslin 2025-03-10 04:13:59 +01:00
parent 54dd958073
commit beba838c0d
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE
2 changed files with 5 additions and 5 deletions

View File

@ -545,18 +545,18 @@ final class NodaTimeSplitter {
// 10000-20000 // 10000-20000
if (!empty(\preg_match("/^[0-9]{5}(\-|\/)[0-9]{5}$/", $datum))) { if (!empty(\preg_match("/^[0-9]{5}(\-|\/)[0-9]{5}$/", $datum))) {
return new NodaSplitTime(start_year: \substr($datum, 0, 5), end_year: \substr($datum, 6, 5)); return new NodaSplitTime(start_year: \substr($datum, 0, 5), end_year: \substr($datum, -5));
} }
// 0000-0000 // 0000-0000
if (\preg_match("/^[0-9]{4}(\-|\/|\)[0-9]{4}(\.|)$/", $datum)) { if (\preg_match("/^[0-9]{4}(\-|\/|\)[0-9]{4}(\.|)$/", $datum)) {
return new NodaSplitTime(start_year: \substr($datum, 0, 4), end_year: \substr($datum, 5, 4)); return new NodaSplitTime(start_year: \substr($datum, 0, 4), end_year: \substr($datum, -4));
} }
// 1.900-2.000 // 1.900-2.000
if (\preg_match("/^[0-9]\.[0-9][0-9][0-9](\-|\/|\)[0-9]\.[0-9][0-9][0-9]$/", $datum)) { if (\preg_match("/^[0-9]\.[0-9][0-9][0-9](\-|\/|\)[0-9]\.[0-9][0-9][0-9]$/", $datum)) {
$datum = \str_replace(".", "", $datum); $datum = \str_replace(".", "", $datum);
return new NodaSplitTime(start_year: \substr($datum, 0, 4), end_year: \substr($datum, 5, 4)); return new NodaSplitTime(start_year: \substr($datum, 0, 4), end_year: \substr($datum, -4));
} }
// German TT.MM.JJJJ / TT.MM.JJJ / TT.MM.JJ / TT.MM.J // German TT.MM.JJJJ / TT.MM.JJJ / TT.MM.JJ / TT.MM.J
@ -601,7 +601,7 @@ final class NodaTimeSplitter {
// Intl': 2020-12 // Intl': 2020-12
if (\preg_match("/^[0-9]{4}\-[0-9]{2}$/", $datum)) { // German Y-m or 1912-15 if (\preg_match("/^[0-9]{4}\-[0-9]{2}$/", $datum)) { // German Y-m or 1912-15
$year = \substr($datum, 0, 4); $year = \substr($datum, 0, 4);
$month = \substr($datum, 5, 2); $month = \substr($datum, -2);
// Assume the end is a month // Assume the end is a month
if (intval($month) < 12) { if (intval($month) < 12) {

View File

@ -164,7 +164,7 @@ final class NodaTimeSplitterTest extends TestCase {
new NodaSplitTime('1930', '2017', new NodaSplitTime('1930', '2017',
start_date: '1930-01-01', start_date: '1930-01-01',
end_date: '2017-12-31'), end_date: '2017-12-31'),
"19302017", "1930-2017",
], ],
]; ];