From 37715bc3e855fa073f4a570a27f970f03b0ffe2c Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Sun, 15 Oct 2023 19:20:16 +0200 Subject: [PATCH] Support BCE / CE times --- src/NodaTimeSplitter.php | 4 +++- tests/NodaTimeSplitterTest.php | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/NodaTimeSplitter.php b/src/NodaTimeSplitter.php index 960c44a..6a9cbc0 100644 --- a/src/NodaTimeSplitter.php +++ b/src/NodaTimeSplitter.php @@ -66,6 +66,8 @@ final class NodaTimeSplitter { // To clean "v.Chr." => "v. Chr.", "v. Chr" => "v. Chr.", + "BCE" => "v. Chr.", + "CE" => "", "vor Christus" => "v. Chr.", ]; @@ -399,7 +401,7 @@ final class NodaTimeSplitter { $datum = self::clean_input($datum); - if (\preg_match("/\ v\.\ Chr\.$/", $datum)) { + if (\str_ends_with($datum, ' v. Chr.')) { if ($output = self::attempt_splitting(\substr($datum, 0, -8))) { $start = \strval(-1 * \intval($output[1])); $end = \strval(-1 * \intval($output[0])); diff --git a/tests/NodaTimeSplitterTest.php b/tests/NodaTimeSplitterTest.php index 372fd26..912382f 100644 --- a/tests/NodaTimeSplitterTest.php +++ b/tests/NodaTimeSplitterTest.php @@ -428,6 +428,42 @@ final class NodaTimeSplitterTest extends TestCase { } + /** + * Test to check whether the HTML page is correctly generated. + * + * @author Joshua Ramon Enslin + * @group ValidOutput + * + * @return void + */ + public function testSplitSimpleDatesEnglish():void { + + $output = NodaTimeSplitter::attempt_splitting("1925 BCE"); + self::assertEquals($output, [ + 0 => "-1925", + 1 => "-1925", + 2 => "00", + 3 => "00", + 4 => "-", + 5 => "", + ]); + self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1925 v. Chr."); + self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925); + + $output = NodaTimeSplitter::attempt_splitting("1925 CE"); + self::assertEquals($output, [ + 0 => "1925", + 1 => "1925", + 2 => "00", + 3 => "00", + 4 => "+", + 5 => "", + ]); + self::assertEquals(NodaTimeSplitter::timePartsToTimeName($output), "1925"); + self::assertEquals(NodaTimeSplitter::timePartsToCountingYear($output), 1925); + + } + /** * Test to check whether the HTML page is correctly generated. *