Re: Programming a calendar system
From: | Mark J. Reed <markjreed@...> |
Date: | Friday, April 30, 2004, 1:18 |
On Thu, Apr 29, 2004 at 09:02:14PM -0400, Mark J. Reed wrote:
> Argh, argh, argh. You are of course correct. Preceding message results
> incorrect if you want to base it on -14 (= 15 BC),
> although the technique is still valid. Will recompute.
Meanwhile, here's the PHP for the -986 basis. Which tells me that it
is right now 4930-18-02 09:12:63 Aréqan time.
<?
# Units
$SEC_PER_ASEC = 1.2; # Earth seconds per Areqa second
$ASEC_PER_AMIN = 72; # Areqa seconds per minute
$AMIN_PER_AHOUR = 18; # Areqa minutes per hour
$AHOUR_PER_ADAY = 27; # Areqa hours per day
$ADAY_PER_YEAR = 456; # Areqa days per (common) year
$ADAY_PER_TETRAD = 1823; # Areqa days per tetrad
$AYEAR_PER_TETRAD = 4; # Areqa years per tetrad
# Correspondence point
$TIME_T_0 = 50812804.8; # UNIX time_t of correspondence point
$AYEAR_0 = 4877; # Areqa year of correspondence point
# Year layout
$MONTH_LENGTHS = array(25, 25, 25, 25, 25, 25, 24, 26, 30,
26, 26, 24, 25, 25, 25, 25, 25, 25);
# Function to get the quotient and remainder in one go
function divmod($x, $y)
{
$q = floor($x / $y);
$r = $x - $q * $y;
return array ($q, $r);
}
# how many days in month N of year Y
function days_in_month($year, $month)
{
global $MONTH_LENGTHS;
$days = $MONTH_LENGTHS[$month - 1];
if ($month == 9 && $year % 4 == 0) $days -= 1;
return $days;
}
# current time
$now = time(0);
# no. of earth secs since correspondence point
$sec = $now - $TIME_T_0;
# no. of areqa secs since correspondence point
$asec = $sec / $SEC_PER_ASEC;
# convert to higher units
list ($amin, $nsec) = divmod($asec, $ASEC_PER_AMIN);
list ($ahour, $nmin) = divmod($amin, $AMIN_PER_AHOUR);
list ($aday, $nhour) = divmod($ahour, $AHOUR_PER_ADAY);
# now we know that there have been $aday elapsed days
# how many tetrads is that?
list ($atetrad, $nday) = divmod($aday, $ADAY_PER_TETRAD);
# and how many years into the next one?
list ($ayear, $aday) = divmod($nday, $ADAY_PER_YEAR);
# add it all up
$ayear = $atetrad * $AYEAR_PER_TETRAD + $ayear + $AYEAR_0;
# convert to months
$amonth = 1;
while ($aday > days_in_month($ayear, $amonth))
{
$aday -= days_in_month($ayear, $amonth);
$amonth++;
}
# and display the result
printf("%d-%02d-%02d %02d:%02d:%02d\n",
$ayear, $amonth, $aday, $nhour, $nmin, $nsec);
?>