3.16. Using Non-Gregorian Calendars3.16.1. ProblemYou want to use a non-Gregorian calendar, such as a Julian, Jewish, or French Republican calendar. 3.16.2. SolutionPHP's calendar extension provides conversion functions for working with the Julian calendar, as well as the French Republican and Jewish calendars. To use these functions, the calendar extension must be loaded. These functions use the Julian day count (which is different than the Julian calendar) as their intermediate format to move information between them. The two functions jdtogregorian( ) and gregoriantojd( ) convert between Julian days and the familiar Gregorian calendar: $jd = gregoriantojd(3,9,1876); // March 9, 1876; $jd = 2406323 $gregorian = jdtogregorian($jd); // $gregorian = 3/9/1876 The valid range for the Gregorian calendar is 4714 BCE to 9999 CE. 3.16.3. DiscussionTo convert between Julian days and the Julian calendar, use jdtojulian( ) and juliantojd( ): // February 29, 1900 (not a Gregorian leap year) $jd = juliantojd(2,29,1900); // $jd = 2415092 $julian = jdtojulian($jd); // $julian = 2/29/1900 $gregorian = jdtogregorian($jd); // $gregorian = 3/13/1900 The valid range for the Julian calendar is 4713 BCE to 9999 CE, but since it was created in 46 BCE, you run the risk of annoying Julian calendar purists if you use it for dates before that. To convert between Julian days and the French Republican calendar, use jdtofrench( ) and frenchtojd( ): $jd = frenchtojd(8,13,11); // 13 floréal XI; $jd = 2379714 $french = jdtofrench($jd); // $french = 8/13/11 $gregorian = jdtofregorian($jd); // $gregorian = 5/3/1803; sale of Louisiana to U.S. The valid range for the French Republican calendar is September 1792 to September 1806, which is small, but since the calendar was only in use from October 1793 to January 1806, it's comprehensive enough. To convert between Julian days and the Jewish calendar, use jdtojewish( ) and jewishtojd( ): $jd = JewishToJD(6,14,5761); // Adar 14, 5761; $jd = 2451978 $jewish = JDToJewish($jd); // $jewish = 6/14/5761 $gregorian = JDToGregorian($jd); // $gregorian = 3/9/2001 The valid range for the Jewish calendar starts with 3761 BCE (year 1 on the Jewish calendar). 3.16.4. See AlsoDocumentation for the calendar functions at http://www.php.net/calendar; the history of the Gregorian calendar is explained at http://scienceworld.wolfram.com/astronomy/GregorianCalendar.html. Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|