From 1e8b0051fa7dd56f18f359c69aa5dca09623e5f1 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Wed, 7 Nov 2018 15:52:18 +0100 Subject: [PATCH] republicandate: add new array functions Add array functions for different needs (from a romme_datestring, a julian day count or a gregorian date). Simplify functions that need said arrays. --- exemple.php | 1 + republicandate.php | 59 +++++++++++++++++++++++++++++----------------- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/exemple.php b/exemple.php index a5000d1..ef7d39e 100644 --- a/exemple.php +++ b/exemple.php @@ -35,6 +35,7 @@ $testJulianday = gregoriantojd($testMois, $testJour, $testAnnee);

Test des différentes fonctions

jdtoromme :
+ gregoriantoromme :
gregorian2FrenchDateString :
gregorian2FrenchDateStringShort :
diff --git a/republicandate.php b/republicandate.php index 366c936..d4e6599 100644 --- a/republicandate.php +++ b/republicandate.php @@ -86,21 +86,47 @@ function jdtoromme( $juliandaycount ) { return $romme_date_string; } +function gregoriantoromme($m, $d, $y) { + $juliandaycount = gregoriantojd($m, $d, $y); + $romme_date_string = jdtoromme($juliandaycount); + + return $romme_date_string; +} + +function jdtoromme_getArray($juliandaycount) { + $romme_date_string = jdtoromme($juliandaycount); + + $rommeArray = romme_getArray($romme_date_string); + + return $rommeArray; +} + +function gregoriantoromme_getArray($m, $d, $y) { + $romme_date_string = gregoriantoromme($m, $d, $y); + + $rommeArray = romme_getArray($romme_date_string); + + return $rommeArray; +} + +function romme_getArray($romme_date_string) { + $rommeArray = explode("/", $romme_date_string); + + return $rommeArray; +} + + function gregorian2FrenchDateArray($m, $d, $y) { - $julian_date = gregoriantojd($m, $d, $y); - $french = jdtoromme($julian_date); - if($french == "0/0/0") - return "" ; - $dateArray = explode("/", $french) ; + $rommeArray = gregoriantoromme_getArray($m, $d, $y); // get the month name - $monthname = FrenchMonthNames($dateArray[0]) ; + $monthname = FrenchMonthNames($rommeArray[0]) ; /* convert the year number to roman digits (as most historians do and documents of the time did */ - $stryear = $dateArray[2]; + $stryear = $rommeArray[2]; - return array($monthname, $dateArray[1], $stryear ) ; + return array($monthname, $rommeArray[1], $stryear ) ; } function FrenchMonthNames($mo) @@ -179,13 +205,8 @@ function FrenchOrdinalNumber($Day) { } function gregorian2FrenchDateString($m,$d,$y) { - $julian_date = gregoriantojd($m, $d, $y); - $french = jdtoromme($julian_date); + $dateArray = gregoriantoromme_getArray($m,$d,$y); - if($french == "0/0/0") - return "" ; - - $dateArray = explode("/", $french) ; $monthname = FrenchMonthNames($dateArray[0]) ; $dayname = FrenchDayNames($dateArray[1]); @@ -203,13 +224,9 @@ function gregorian2FrenchDateString($m,$d,$y) { } function gregorian2FrenchDateStringShort($m,$d,$y) { - $julian_date = gregoriantojd($m, $d, $y); - $french = jdtoromme($julian_date); - if($french == "0/0/0") - return "" ; - - $dateArray = explode("/", $french) ; - $monthname = FrenchMonthNames($dateArray[0]) ; + $dateArray = gregoriantoromme_getArray($m,$d,$y); + + $monthname = FrenchMonthNames($dateArray[0]); $dayname = FrenchDayNames($dateArray[1]); if ($dateArray[0]==13) {