Ensure duplicate time names can be parsed in NodaTimeSplitter (e.g.
1.1.2024-1.1.2024)
This commit is contained in:
parent
4dcd93b947
commit
b7bb7364d4
|
@ -1208,6 +1208,30 @@ final class NodaTimeSplitter {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes superfluous characters and makes an input string roughly parsable.
|
||||
*
|
||||
* @param string $input Input string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function _runBasicNameCleanup(string $input):string {
|
||||
|
||||
$input = trim(trim($input), ',;');
|
||||
|
||||
// Clean away duplicate inputs
|
||||
// 1440-1440
|
||||
if (str_contains($input, '-')) {
|
||||
$parts = explode('-', $input);
|
||||
if (count($parts) === 2 && $parts[0] === $parts[1]) {
|
||||
$input = $parts[0];
|
||||
}
|
||||
}
|
||||
|
||||
return $input;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper to check if any splitting command works.
|
||||
*
|
||||
|
@ -1217,6 +1241,8 @@ final class NodaTimeSplitter {
|
|||
*/
|
||||
public static function attempt_splitting(string $datum):NodaSplitTime|false {
|
||||
|
||||
$datum = self::_runBasicNameCleanup($datum);
|
||||
|
||||
try {
|
||||
if (!empty($moda = self::is_timespan($datum))) {
|
||||
return $moda;
|
||||
|
|
|
@ -1056,6 +1056,14 @@ final class NodaTimeSplitterTest extends TestCase {
|
|||
self::assertEquals('-1400', $output->start_year);
|
||||
self::assertEquals('-1400-01-01', $output->start_date);
|
||||
|
||||
// Same start as end with day
|
||||
$output = NodaTimeSplitter::attempt_splitting("11.10.1991-11.10.1991");
|
||||
self::assertNotEmpty($output);
|
||||
self::assertEquals('1991', $output->start_year);
|
||||
self::assertEquals('1991-10-11', $output->start_date);
|
||||
self::assertEquals('1991', $output->end_year);
|
||||
self::assertEquals('1991-10-11', $output->end_date);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user