Fix order of split days and months within a single year BCE

Close #32
This commit is contained in:
2025-04-07 18:32:14 +02:00
parent f84fe1bca5
commit dba60dbce6
2 changed files with 20 additions and 8 deletions

View File

@ -345,6 +345,10 @@ final class NodaTimeSplitter {
$start_date = $output->start_date;
$end_date = $output->end_date;
}
else if ($start === $end && (int)str_replace('-', '', $start_date) > (int)str_replace('-', '', $end_date)) {
$start_date = $output->start_date;
$end_date = $output->end_date;
}
return new NodaSplitTime($start, $end, $output->counting_time_month, $output->counting_time_day,
NodaCountingTimeIndicator::bce, $output->before_after_indicator, '-' . $start_date, '-' . $end_date);
}
@ -752,7 +756,7 @@ final class NodaTimeSplitter {
return new NodaSplitTime($year, $year);
}
if (str_starts_with($inpDateWoSpaces, '0-') || str_ends_with($inpDateWoSpaces, '-0') && \preg_match("/^[0-9]{4}$/", \strtr($inpDateWoSpaces, ['-0' => '', '0-' => '']))) {
if ((str_starts_with($inpDateWoSpaces, '0-') || str_ends_with($inpDateWoSpaces, '-0')) && \preg_match("/^[0-9]{4}$/", \strtr($inpDateWoSpaces, ['-0' => '', '0-' => ''])) && !str_ends_with($inpDateWoSpaces, '0-0')) {
$year = \strtr($inpDateWoSpaces, ['-0' => '', '0-' => '']);
if (strlen($year) === 4) {
return new NodaSplitTime($year, $year);