Allow splitting times after <year><month>
This commit is contained in:
parent
be46c39efd
commit
a0037c9883
|
@ -182,7 +182,7 @@ final class NodaTimeAutotranslater {
|
|||
'es' => 'Despues de %s',
|
||||
'fa' => '%s-',
|
||||
'fr' => 'Après %s',
|
||||
'hu' => '%s-után',
|
||||
'hu' => '%s után',
|
||||
'id' => 'Setelah %s',
|
||||
'it' => 'Dopo il %s',
|
||||
'ka' => '%s წლის შემდეგ',
|
||||
|
@ -232,7 +232,7 @@ final class NodaTimeAutotranslater {
|
|||
'es' => 'Antes de %s',
|
||||
'fa' => '-%s',
|
||||
'fr' => 'Avant %s',
|
||||
'hu' => '%s-előtt',
|
||||
'hu' => '%s előtt',
|
||||
'id' => 'Sebelum %s',
|
||||
'it' => 'Prima del %s',
|
||||
'ka' => '%s წლამდე',
|
||||
|
@ -246,8 +246,8 @@ final class NodaTimeAutotranslater {
|
|||
'tr' => '%s-',
|
||||
|
||||
// Languages that don't really need a specific locale
|
||||
'ja' => '%sまで',
|
||||
'zh' => '直到%s',
|
||||
'ja' => '%s以前',
|
||||
'zh' => '%s之前',
|
||||
];
|
||||
|
||||
const LANGS_CENTURY_FORMAT = [
|
||||
|
@ -269,8 +269,8 @@ final class NodaTimeAutotranslater {
|
|||
'ta' => '%s ஆம் நூற்றாண்டு',
|
||||
'tl' => 'Ika-%s na siglo',
|
||||
'tr' => '%s. yüzyıl',
|
||||
'ja' => '%s以前',
|
||||
'zh' => '%s之前',
|
||||
'ja' => '%s世紀',
|
||||
'zh' => '%s世紀',
|
||||
];
|
||||
|
||||
const LANGS_CENTURIES_FORMAT = [
|
||||
|
|
|
@ -190,7 +190,7 @@ final class NodaTimeSplitter {
|
|||
public static function timePartsToTimeName(array $moda):string {
|
||||
|
||||
if (!empty($moda[5]) and $moda[5] === "Nach" and $moda[1] === "?") {
|
||||
$moda[0] = strval(intval($moda[0]) - 1);
|
||||
if (empty(trim($moda[2], "0 "))) $moda[0] = strval(intval($moda[0]) - 1);
|
||||
$moda[1] = $moda[0];
|
||||
$prefix = "Nach ";
|
||||
}
|
||||
|
@ -250,7 +250,7 @@ final class NodaTimeSplitter {
|
|||
}
|
||||
|
||||
if ($moda[1] === "?") {
|
||||
if (!empty($moda[5]) and $moda[5] === "Nach") {
|
||||
if (!empty($moda[5]) and $moda[5] === "Nach" and empty(trim($moda[2], " 0"))) {
|
||||
return abs(intval($moda[0])) - 1;
|
||||
}
|
||||
return abs(intval($moda[0]));
|
||||
|
@ -681,13 +681,19 @@ final class NodaTimeSplitter {
|
|||
return ["?", $start, "00", "00", "+", ""];
|
||||
}
|
||||
|
||||
if (preg_match("/^(Nach|nach)\ [0-9]{4}/", $datum)) {
|
||||
if (preg_match("/^(Nach|nach)\ /", $datum)) {
|
||||
if (($spacePos = strpos($datum, " ")) === false) {
|
||||
return [];
|
||||
}
|
||||
if ($output = self::attempt_splitting(substr($datum, $spacePos))) {
|
||||
|
||||
// Handle cases like "Nach 60er Jahre" with divergent start and end year
|
||||
if ($output[1] !== $output[0] and intval($output[1]) > intval($output[0])) {
|
||||
$output[0] = $output[1];
|
||||
}
|
||||
|
||||
$output[1] = "?";
|
||||
$output[0] = strval((intval($output[0]) + 1));
|
||||
if (empty(trim($output[2], "0 .,"))) $output[0] = strval((intval($output[0]) + 1));
|
||||
$output[5] = "Nach";
|
||||
return $output;
|
||||
}
|
||||
|
@ -697,8 +703,14 @@ final class NodaTimeSplitter {
|
|||
return [];
|
||||
}
|
||||
if ($output = self::attempt_splitting(substr($datum, 0, $spacePos))) {
|
||||
|
||||
// Handle cases like "Nach 60er Jahre" with divergent start and end year
|
||||
if ($output[1] !== $output[0] and intval($output[1]) > intval($output[0])) {
|
||||
$output[0] = $output[1];
|
||||
}
|
||||
|
||||
$output[1] = "?";
|
||||
$output[0] = strval((intval($output[0]) + 1));
|
||||
if (empty(trim($output[2], "0 .,"))) $output[0] = strval((intval($output[0]) + 1));
|
||||
$output[5] = "Nach";
|
||||
return $output;
|
||||
}
|
||||
|
|
|
@ -144,6 +144,30 @@ final class NodaTimeSplitterTest extends TestCase {
|
|||
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1920-1929");
|
||||
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925);
|
||||
|
||||
$output = NodaTimeSplitter::attempt_splitting("Nach Januar 2020");
|
||||
self::assertEquals($output, [
|
||||
0 => "2020",
|
||||
1 => "?",
|
||||
2 => "01",
|
||||
3 => "00",
|
||||
4 => "+",
|
||||
5 => "Nach",
|
||||
]);
|
||||
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Nach Januar 2020");
|
||||
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
|
||||
|
||||
$output = NodaTimeSplitter::attempt_splitting("Nach 60er Jahre");
|
||||
self::assertEquals($output, [
|
||||
0 => "1970",
|
||||
1 => "?",
|
||||
2 => "00",
|
||||
3 => "00",
|
||||
4 => "+",
|
||||
5 => "Nach",
|
||||
]);
|
||||
self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "Nach 1969");
|
||||
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1969);
|
||||
|
||||
$output = NodaTimeSplitter::attempt_splitting("Nach 2020");
|
||||
self::assertEquals($output, [
|
||||
0 => "2021",
|
||||
|
@ -473,8 +497,8 @@ final class NodaTimeSplitterTest extends TestCase {
|
|||
$output = NodaTimeSplitter::attempt_splitting("Januar-Februar");
|
||||
self::assertEquals($output, []);
|
||||
|
||||
$output = NodaTimeSplitter::attempt_splitting("Nach Januar 1944");
|
||||
self::assertEquals($output, []);
|
||||
# $output = NodaTimeSplitter::attempt_splitting("Nach 1944-1964");
|
||||
# self::assertEquals($output, []);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user