MDNodaHelpers/tests/NodaTimeSplitterTest.php

1346 lines
47 KiB
PHP

<?PHP
/**
* This script contains tests for the time name splitter.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Small;
use PHPUnit\Framework\Attributes\DataProvider;
/**
* This script contains tests for the time name splitter.
*/
#[small]
#[CoversClass(\NodaTimeSplitter::class)]
final class NodaTimeSplitterTest extends TestCase {
/**
* Test to check whether the HTML page is correctly generated.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
* @group ValidOutput
* @small
*
* @return void
*/
public function testSplitSimpleDatesGerman():void {
$output = NodaTimeSplitter::attempt_splitting("2. Januar 2020");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "2020",
1 => "2020",
2 => "01",
3 => "02",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "02.01.2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("02.1.25 v. Chr");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "-25",
1 => "-25",
2 => "01",
3 => "02",
4 => "-",
5 => "",
]);
self::assertEquals($output->toTimeName(), "02.01.25 v. Chr.");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 25);
$output = NodaTimeSplitter::attempt_splitting("2.01.25 v. Chr");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "-25",
1 => "-25",
2 => "01",
3 => "02",
4 => "-",
5 => "",
]);
self::assertEquals($output->toTimeName(), "02.01.25 v. Chr.");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 25);
$output = NodaTimeSplitter::attempt_splitting("02.01.25 v. Chr");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "-25",
1 => "-25",
2 => "01",
3 => "02",
4 => "-",
5 => "",
]);
self::assertEquals($output->toTimeName(), "02.01.25 v. Chr.");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 25);
$output = NodaTimeSplitter::attempt_splitting("2.1.25 v. Chr");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "-25",
1 => "-25",
2 => "01",
3 => "02",
4 => "-",
5 => "",
]);
self::assertEquals($output->toTimeName(), "02.01.25 v. Chr.");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 25);
$output = NodaTimeSplitter::attempt_splitting("2.1.2020");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "2020",
1 => "2020",
2 => "01",
3 => "02",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "02.01.2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("02.01.2020");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "2020",
1 => "2020",
2 => "01",
3 => "02",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "02.01.2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("?.1.2020");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "2020",
1 => "2020",
2 => "01",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "Januar 2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("?.11.2020");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "2020",
1 => "2020",
2 => "11",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "November 2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting(".2020");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "2020",
1 => "2020",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("0-2020");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "2020",
1 => "2020",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("2020-0");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "2020",
1 => "2020",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("? 2020");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "2020",
1 => "2020",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("?.?.2020");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "2020",
1 => "2020",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("1920-1929");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1920",
1 => "1929",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "1920-1929");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925);
$output = NodaTimeSplitter::attempt_splitting("20er");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1920",
1 => "1929",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "1920-1929");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925);
$output = NodaTimeSplitter::attempt_splitting("1920-1929");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1920",
1 => "1929",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "1920-1929");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925);
$output = NodaTimeSplitter::attempt_splitting("1920er Jahre");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1920",
1 => "1929",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "1920-1929");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925);
$output = NodaTimeSplitter::attempt_splitting("Vor Dezember 2020");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "?",
1 => "2020",
2 => "12",
3 => "00",
4 => "+",
5 => "Vor",
]);
self::assertEquals($output->toTimeName(), "Vor Dezember 2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("Vor 2020");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "?",
1 => "2019",
2 => "00",
3 => "00",
4 => "+",
5 => "Vor",
]);
self::assertEquals($output->toTimeName(), "Vor 2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("Nach Januar 2020");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "2020",
1 => "?",
2 => "01",
3 => "00",
4 => "+",
5 => "Nach",
]);
self::assertEquals($output->toTimeName(), "Nach Januar 2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("Januar 2020");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "2020",
1 => "2020",
2 => "01",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "Januar 2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("Januar 1217");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1217",
1 => "1217",
2 => "01",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "Januar 1217");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1217);
$output = NodaTimeSplitter::attempt_splitting("Januar 1520");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1520",
1 => "1520",
2 => "01",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "Januar 1520");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1520);
$output = NodaTimeSplitter::attempt_splitting("Januar 1001");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1001",
1 => "1001",
2 => "01",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "Januar 1001");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1001);
$output = NodaTimeSplitter::attempt_splitting("Januar 2780");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "2780",
1 => "2780",
2 => "01",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "Januar 2780");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2780);
$output = NodaTimeSplitter::attempt_splitting("Nach 60er Jahre");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1970",
1 => "?",
2 => "00",
3 => "00",
4 => "+",
5 => "Nach",
]);
self::assertEquals($output->toTimeName(), "Nach 1969");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1969);
$output = NodaTimeSplitter::attempt_splitting("Nach 2020");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "2021",
1 => "?",
2 => "00",
3 => "00",
4 => "+",
5 => "Nach",
]);
self::assertEquals($output->toTimeName(), "Nach 2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("Bis Januar 2020");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "?",
1 => "2020",
2 => "01",
3 => "00",
4 => "+",
5 => "Bis",
]);
self::assertEquals($output->toTimeName(), "Bis Januar 2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("Januar 2020");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "2020",
1 => "2020",
2 => "01",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "Januar 2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
// Intl' month: 2020-01
$output = NodaTimeSplitter::attempt_splitting("2020-01");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "2020",
1 => "2020",
2 => "01",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "Januar 2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("Januar 2020 v. Chr.");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "-2020",
1 => "-2020",
2 => "01",
3 => "00",
4 => "-",
5 => "",
]);
self::assertEquals($output->toTimeName(), "Januar 2020 v. Chr.");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
// 5-Digit timespans BCE
$output = NodaTimeSplitter::attempt_splitting("40000-25000 vor Christus");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "-40000",
1 => "-25000",
2 => "00",
3 => "00",
4 => "-",
5 => "",
]);
self::assertEquals($output->toTimeName(), "40000-25000 v. Chr.");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 32500);
// 5-Digit timespans BCE
$output = NodaTimeSplitter::attempt_splitting("40000-25000 v.C.");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "-40000",
1 => "-25000",
2 => "00",
3 => "00",
4 => "-",
5 => "",
]);
self::assertEquals($output->toTimeName(), "40000-25000 v. Chr.");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 32500);
$output = NodaTimeSplitter::attempt_splitting("20. Jahrhundert v. Chr.");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "-2000",
1 => "-1901",
2 => "00",
3 => "00",
4 => "-",
5 => "",
]);
self::assertEquals($output->toTimeName(), "2000-1901 v. Chr.");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1950);
$output = NodaTimeSplitter::attempt_splitting("20. Jh.");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1901",
1 => "2000",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "1901-2000");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1951);
$output = NodaTimeSplitter::attempt_splitting("20. Jhd.");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1901",
1 => "2000",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "1901-2000");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1951);
$output = NodaTimeSplitter::attempt_splitting("20. Jhdt.");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1901",
1 => "2000",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "1901-2000");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1951);
$output = NodaTimeSplitter::attempt_splitting("20. Jahrhundert");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1901",
1 => "2000",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "1901-2000");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1951);
$output = NodaTimeSplitter::attempt_splitting("1945-48");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1945",
1 => "1948",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "1945-1948");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1947);
$output = NodaTimeSplitter::attempt_splitting("1945 und 1946");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1945",
1 => "1946",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "1945-1946");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1946);
$output = NodaTimeSplitter::attempt_splitting("1945 oder 1946");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1945",
1 => "1946",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "1945-1946");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1946);
$output = NodaTimeSplitter::attempt_splitting("20.-19. Jahrhundert v. Chr.");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "-2000",
1 => "-1801",
2 => "00",
3 => "00",
4 => "-",
5 => "",
]);
self::assertEquals($output->toTimeName(), "2000-1801 v. Chr.");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1900);
$output = NodaTimeSplitter::attempt_splitting("Bis 20.-19. Jahrhundert v. Chr.");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "?",
1 => "-1801",
2 => "00",
3 => "00",
4 => "-",
5 => "Bis",
]);
self::assertEquals($output->toTimeName(), "Bis 1801 v. Chr.");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1801);
$output = NodaTimeSplitter::attempt_splitting("15. 11. 1978");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1978",
1 => "1978",
2 => "11",
3 => "15",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "15.11.1978");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1978);
$output = NodaTimeSplitter::attempt_splitting("6 November 1978");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1978",
1 => "1978",
2 => "11",
3 => "06",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "06.11.1978");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1978);
}
/**
* Test to check whether the HTML page is correctly generated.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
* @group ValidOutput
* @small
*
* @return void
*/
public function testSplitSimpleDatesEnglish():void {
$output = NodaTimeSplitter::attempt_splitting("1925 BCE");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "-1925",
1 => "-1925",
2 => "00",
3 => "00",
4 => "-",
5 => "",
]);
self::assertEquals($output->toTimeName(), "1925 v. Chr.");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925);
$output = NodaTimeSplitter::attempt_splitting("1925 CE");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1925",
1 => "1925",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "1925");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925);
}
/**
* Test to check whether the HTML page is correctly generated.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
* @group ValidOutput
* @small
*
* @return void
*/
public function testSplitSimpleDatesHungarian():void {
$output = NodaTimeSplitter::attempt_splitting("Kr. e. 2. század");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "-200",
1 => "-101",
2 => "00",
3 => "00",
4 => "-",
5 => "",
]);
self::assertEquals($output->toTimeName(), "200-101 v. Chr.");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 150);
$output = NodaTimeSplitter::attempt_splitting("2020.01.02.");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "2020",
1 => "2020",
2 => "01",
3 => "02",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "02.01.2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("2020. januar. 2.");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "2020",
1 => "2020",
2 => "01",
3 => "02",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "02.01.2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("2020.01.2.");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "2020",
1 => "2020",
2 => "01",
3 => "02",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "02.01.2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("2020.1.2.");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "2020",
1 => "2020",
2 => "01",
3 => "02",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "02.01.2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("2020. Januar 2.");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "2020",
1 => "2020",
2 => "01",
3 => "02",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "02.01.2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("2020-01-02");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "2020",
1 => "2020",
2 => "01",
3 => "02",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "02.01.2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("1920-tól 1929-ig");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1920",
1 => "1929",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "1920-1929");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925);
$output = NodaTimeSplitter::attempt_splitting("1920-1929 között");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1920",
1 => "1929",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "1920-1929");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925);
$output = NodaTimeSplitter::attempt_splitting("1920-től 1929-ig");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1920",
1 => "1929",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "1920-1929");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925);
// From 1920 onwards
$output = NodaTimeSplitter::attempt_splitting("1920 utántól");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1920",
1 => "?",
2 => "00",
3 => "00",
4 => "+",
5 => "Seit",
]);
self::assertEquals($output->toTimeName(), "Seit 1920");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1920);
$output = NodaTimeSplitter::attempt_splitting("1920-es évek");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1920",
1 => "1929",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "1920-1929");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925);
$output = NodaTimeSplitter::attempt_splitting("1920-es évekig");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "?",
1 => "1929",
2 => "00",
3 => "00",
4 => "+",
5 => "Bis",
]);
self::assertEquals($output->toTimeName(), "Bis 1929");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1929);
$output = NodaTimeSplitter::attempt_splitting("2020. Januar");
self::assertNotEmpty($output);
self::assertEquals([
0 => "2020",
1 => "2020",
2 => "01",
3 => "00",
4 => "+",
5 => "",
], $output->toOldFormat());
self::assertEquals($output->toTimeName(), "Januar 2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("Kr. e. 2020. Januar");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "-2020",
1 => "-2020",
2 => "01",
3 => "00",
4 => "-",
5 => "",
]);
self::assertEquals($output->toTimeName(), "Januar 2020 v. Chr.");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
$output = NodaTimeSplitter::attempt_splitting("20. sz");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1901",
1 => "2000",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "1901-2000");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1951);
$output = NodaTimeSplitter::attempt_splitting("III. század");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "201",
1 => "300",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "201-300 n. Chr.");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 251);
$output = NodaTimeSplitter::attempt_splitting("20th century");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1901",
1 => "2000",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "1901-2000");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1951);
$output = NodaTimeSplitter::attempt_splitting("20. század");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1901",
1 => "2000",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "1901-2000");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1951);
$output = NodaTimeSplitter::attempt_splitting("20.század");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "1901",
1 => "2000",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "1901-2000");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1951);
$output = NodaTimeSplitter::attempt_splitting("Kr. e. 20. század");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "-2000",
1 => "-1901",
2 => "00",
3 => "00",
4 => "-",
5 => "",
]);
self::assertEquals($output->toTimeName(), "2000-1901 v. Chr.");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1950);
$output = NodaTimeSplitter::attempt_splitting("Kr. e. 20.-19. század");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "-2000",
1 => "-1801",
2 => "00",
3 => "00",
4 => "-",
5 => "",
]);
self::assertEquals($output->toTimeName(), "2000-1801 v. Chr.");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1900);
$output = NodaTimeSplitter::attempt_splitting("Kr. e. 20.-19. század-ig");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "?",
1 => "-1801",
2 => "00",
3 => "00",
4 => "-",
5 => "Bis",
]);
self::assertEquals($output->toTimeName(), "Bis 1801 v. Chr.");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1801);
/*
* TODO
$output = NodaTimeSplitter::attempt_splitting("1900 előtt");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "?",
1 => "1899",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "Vor 1900");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1899);
*/
$output = NodaTimeSplitter::attempt_splitting("1900-ig");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "?",
1 => "1900",
2 => "00",
3 => "00",
4 => "+",
5 => "Bis",
]);
self::assertEquals($output->toTimeName(), "Bis 1900");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1900);
$output = NodaTimeSplitter::attempt_splitting("1900ig");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "?",
1 => "1900",
2 => "00",
3 => "00",
4 => "+",
5 => "Bis",
]);
self::assertEquals($output->toTimeName(), "Bis 1900");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1900);
$output = NodaTimeSplitter::attempt_splitting("2020. december előtt");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "?",
1 => "2020",
2 => "12",
3 => "00",
4 => "+",
5 => "Vor",
]);
self::assertEquals($output->toTimeName(), "Vor Dezember 2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
}
/**
* Test to check whether the HTML page is correctly generated.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
* @group ValidOutput
* @small
*
* @return void
*/
public function testSplitSimpleDatesUkrainian():void {
$output = NodaTimeSplitter::attempt_splitting("2020 p");
self::assertNotEmpty($output);
self::assertEquals($output->toOldFormat(), [
0 => "2020",
1 => "2020",
2 => "00",
3 => "00",
4 => "+",
5 => "",
]);
self::assertEquals($output->toTimeName(), "2020");
self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 2020);
}
/**
* Data provider for time names that the time splitter should not
* be able to split.
*
* @return array<array{0: string, 1: array{start_name: string, end_name: string, start_year: string, end_year: string, start_date: string, end_date: string, counting_time_year: string, counting_time_month: string, counting_time_day: string, counting_time_bcce: string}}>
*/
public static function timeNamesToSplitFromTillProvider():array {
$output = [];
foreach ([
"2004.01.-2004.02." => [
'start_name' => "Januar 2004",
'end_name' => "Februar 2004",
"start_year" => '2004',
"end_year" => '2004',
'start_date' => '2004-01-01',
'end_date' => '2004-02-31',
"counting_time_year" => "2004",
"counting_time_month" => "02",
"counting_time_day" => "01",
"counting_time_bcce" => "+",
],
"2004.01.-02." => [
'start_name' => "Januar 2004",
'end_name' => "Februar 2004",
"start_year" => '2004',
"end_year" => '2004',
'start_date' => '2004-01-01',
'end_date' => '2004-02-31',
"counting_time_year" => "2004",
"counting_time_month" => "02",
"counting_time_day" => "01",
"counting_time_bcce" => "+",
],
"2003.04-05." => [
'start_name' => "April 2003",
'end_name' => "Mai 2003",
"start_year" => '2003',
"end_year" => '2003',
'start_date' => '2003-04-01',
'end_date' => '2003-05-31',
"counting_time_year" => "2003",
"counting_time_month" => "05",
"counting_time_day" => "01",
"counting_time_bcce" => "+",
],
"1981. július-augusztus" => [
'start_name' => "Juli 1981",
'end_name' => "August 1981",
"start_year" => '1981',
"end_year" => '1981',
'start_date' => '1981-07-01',
'end_date' => '1981-08-31',
"counting_time_year" => "1981",
"counting_time_month" => "08",
"counting_time_day" => "01",
"counting_time_bcce" => "+",
],
"2019.03.14.,04.15." => [
'start_name' => "14.03.2019",
'end_name' => "15.04.2019",
"start_year" => '2019',
"end_year" => '2019',
'start_date' => '2019-03-14',
'end_date' => '2019-04-15',
"counting_time_year" => "2019",
"counting_time_month" => "03",
"counting_time_day" => "30",
"counting_time_bcce" => "+",
],
"14.-15.03.2019" => [
'start_name' => "14.03.2019",
'end_name' => "15.03.2019",
"start_year" => '2019',
"end_year" => '2019',
'start_date' => '2019-03-14',
'end_date' => '2019-03-15',
"counting_time_year" => "2019",
"counting_time_month" => "03",
"counting_time_day" => "15",
"counting_time_bcce" => "+",
],
"3.-7.9.1819" => [
'start_name' => "03.09.1819",
'end_name' => "07.09.1819",
"start_year" => '1819',
"end_year" => '1819',
'start_date' => '1819-09-03',
'end_date' => '1819-09-07',
"counting_time_year" => "1819",
"counting_time_month" => "09",
"counting_time_day" => "05",
"counting_time_bcce" => "+",
],
"3.-15.9.1819" => [
'start_name' => "03.09.1819",
'end_name' => "15.09.1819",
"start_year" => '1819',
"end_year" => '1819',
'start_date' => '1819-09-03',
'end_date' => '1819-09-15',
"counting_time_year" => "1819",
"counting_time_month" => "09",
"counting_time_day" => "09",
"counting_time_bcce" => "+",
],
"14.-15.9.1819" => [
'start_name' => "14.09.1819",
'end_name' => "15.09.1819",
"start_year" => '1819',
"end_year" => '1819',
'start_date' => '1819-09-14',
'end_date' => '1819-09-15',
"counting_time_year" => "1819",
"counting_time_month" => "09",
"counting_time_day" => "15",
"counting_time_bcce" => "+",
],
"14.-15.11.1819" => [
'start_name' => "14.11.1819",
'end_name' => "15.11.1819",
"start_year" => '1819',
"end_year" => '1819',
'start_date' => '1819-11-14',
'end_date' => '1819-11-15',
"counting_time_year" => "1819",
"counting_time_month" => "11",
"counting_time_day" => "15",
"counting_time_bcce" => "+",
],
"2019.03.14-15" => [
'start_name' => "14.03.2019",
'end_name' => "15.03.2019",
"start_year" => '2019',
"end_year" => '2019',
'start_date' => '2019-03-14',
'end_date' => '2019-03-15',
"counting_time_year" => "2019",
"counting_time_month" => "03",
"counting_time_day" => "15",
"counting_time_bcce" => "+",
],
"17-19.század" => [
'start_name' => "1601",
'end_name' => "1900",
"start_year" => '1601',
"end_year" => '1900',
'start_date' => '1601-01-01',
'end_date' => '1900-12-31',
"counting_time_year" => "1751",
"counting_time_month" => "01",
"counting_time_day" => "01",
"counting_time_bcce" => "+",
],
"1950-60-as évek" => [
'start_name' => "1950",
'end_name' => "1969",
"start_year" => '1950',
"end_year" => '1969',
'start_date' => '1950-01-01',
'end_date' => '1969-12-31',
"counting_time_year" => "1960",
"counting_time_month" => "01",
"counting_time_day" => "01",
"counting_time_bcce" => "+",
],
] as $in => $out) {
$output[$in] = [$in, $out];
}
return $output;
}
/**
* Test to check special cases can be parsed.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
* @group ValidOutput
* @small
*
* @param string $time_name Input time name.
* @param array{start_name: string, end_name: string, start_year: string, end_year: string, start_date: string, end_date: string, counting_time_year: string, counting_time_month: string, counting_time_day: string, counting_time_bcce: string} $expected Expected values.
*
* @return void
*/
#[DataProvider('timeNamesToSplitFromTillProvider')]
public function testSplittingFromTill(string $time_name, array $expected):void {
// Regular
$output = NodaTimeSplitter::attempt_splitting_from_till($time_name);
self::assertNotEmpty($output);
self::assertEquals($output, $expected);
}
/**
* Special cases for timespans.
*
* @return void
*/
public function testSpecialCasesForTimespans():void {
// Rewritten / 1950-60-as évek
$output = NodaTimeSplitter::attempt_splitting("1400-1100 v. Chr.");
self::assertNotEmpty($output);
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);
}
/**
* Data provider for time names that the time splitter should not
* be able to split.
*
* @return array<array{0: string}>
*/
public static function nonSplittableNamesProvider():array {
$output = [
'empty string' => [''],
];
foreach ([
"1.2.2020-2.2.2020",
"2020 Januar 2-2020 Februar 2",
"2020 Januar-2020 Februar",
"Januar-Februar",
"13.13.2022",
"2022-13-13",
"40.10.2022",
"2022-10-40",
"6;November 1978",
"65497028c51eb",
"6552cf08b0196 test tag",
"1978. július7",
"1978. július 7 elött",
"Anfang September 1903",
] as $entry) {
$output[$entry] = [$entry];
}
return $output;
}
/**
* Test to check whether the HTML page is correctly generated.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
* @group ValidOutput
* @small
*
* @param string $unsplittable_name Name that the time splitter should not
* be able to split.
*
* @return void
*/
#[DataProvider('nonSplittableNamesProvider')]
public function testSplitDoesNotWorkWhenItShouldNot(string $unsplittable_name):void {
$output = NodaTimeSplitter::attempt_splitting($unsplittable_name);
self::assertEmpty($output, "Time name $unsplittable_name should not be split. It was split into:" . PHP_EOL . PHP_EOL . var_export($output, true));
}
}