note 64056 added to function.jdtofrench

From: Date: Thu, 06 Apr 2006 15:25:53 +0000
Subject: note 64056 added to function.jdtofrench
Groups: php.notes 
Request: Send a blank email to php-notes+get-107443@lists.php.net to get a copy of this message
ignivs remarks have been very helpful, as older versions of the documentation had an error Nevertheless his code example can be a bit misleading: $julian_date = juliantojd("09","18","1793"); $french_date = jdtofrench($julian_date); echo $french_date; //will print 1/8/2 //Enjoy e.g. for the date of Napoleon's coup d'état (which has been November, 9, 1799) the code will return: "2/29/8" ; which is WRONG: the day Napoleon overthrew the Directoire to become "Consul" of the French Republic (and later Emperor) was the 18th Brumaire (2nd month in the revolutionary calendar) of Year VIII. The writer of the function assumed, quite reasonably in the context of the other calendar related functions, that the regular input date is JULIAN (even if this doesn't make very much sense in most contexts; converting the date of the old Russian calendar to the French revolutionary calendar might be a funny exercise, yet one which, in most cases, doesn't tend to be really necessary or helpful) In short, to obtain a correct output, a standard date should be converted using the function gregoriantojd(). Here is a small piece of code to obtain the string data for a correctly converted gregorian date: $arDateFrench = gregorian2FrenchDateArray(11, 9, 1799) ; echo $arDateFrench[1] . "&nbsp;" . $arDateFrench[0] . "&nbsp;" . $arDateFrench[2] ; /* the output will be: 18 Brumaire VIII */ function gregorian2FrenchDateArray($m, $d, $y) { $julian_date = gregoriantojd($m, $d, $y); $french = jdtofrench($julian_date); if($french == "0/0/0") return "" ; $arD = split("/", $french) ; // get the month name $monthname = FrenchMonthNames($arD[0]) ; /* convert the year number to roman digits (as most historians do and documents of the time did */ $stryear = decrom($arD[2]) ; return array($monthname, $arD[1], $stryear ) ; } function FrenchMonthNames($mo) { /* The names have been invented by Fabre d'Églantine, a second or rather third rank poet of primarily pastoral poems, with each name referring to the respective period in the agricultural year; e.g. "Vendémiaire" (approx. September) is derived from "vendange" ("harvest"), "Brumaire" (Ocotober/November) from "brume" ("fog") and so on ... */ $arMo = array("Vendémiaire", "Brumaire", "Frimaire", "Nivôse", "Pluviôse", "Ventôse", "Germinal", "Floréal", "Prairial", "Messidor", "Thermidor", "Fructidor", "Sansculottide") ; if($mo < count($arMo)+1) return $arMo[$mo-1] ; } function decrom($dec){ $digits=array( 1 => "I", 4 => "IV", 5 => "V", 9 => "IX", 10 => "X", 40 => "XL", 50 => "L", 90 => "XC", 100 => "C", 400 => "CD", 500 => "D", 900 => "CM", 1000 => "M" ); krsort($digits); $retval=""; foreach($digits as $key => $value){ while($dec>=$key){ $dec-=$key; $retval.=$value; } } return $retval; } ---- Server IP: 216.194.113.175 Probable Submitter: 84.163.202.103 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.jdtofrench.php Edit -- http://master.php.net/note/edit/64056 Del: integrated -- http://master.php.net/note/delete/64056/integrated Del: useless -- http://master.php.net/note/delete/64056/useless Del: bad code -- http://master.php.net/note/delete/64056/bad+code Del: spam -- http://master.php.net/note/delete/64056/spam Del: non-english -- http://master.php.net/note/delete/64056/non-english Del: in docs -- http://master.php.net/note/delete/64056/in+docs Del: other reasons-- http://master.php.net/note/delete/64056 Reject -- http://master.php.net/note/reject/64056 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#107443) next »