Hi!
I’ve found myself in a bit of a mess. I’m an anthropologist with very limited coding experience, and I’ve been working on a Canaanite lunar calendar. The math’s done, and I’ve got a table that can output dates, but I need to add holidays and I’m not sure where to go from there.
Alex at time-meddler.co.uk has been of great help, but unfortunately doesn’t have the time to help me finish this out. Some of this code is his:
[php]
<?php
session_start ();
# orecha_test.php - test script for Israelite lunar calendar
include "includes/gregorian.inc";
include "includes/orecha.inc";
include "includes/html.inc";
include "includes/common.inc";
$title = "Israelite Calendar Test Script";
html_begin ($title,"");
$this_year = date('Y');
$test_year = 2014; // Change this to query different Gregorian years.
print "
$test_year";
$start_date = fixed_from_gregorian($test_year, 1, 1);
$end_date = fixed_from_gregorian($test_year, 12, 31);
print "
";
for ($test_date = $start_date; $test_date <= $end_date; $test_date++) {
print "";
$gregorian_from_fixed = gregorian_from_fixed($test_date);
$greg_day = $gregorian_from_fixed[0];
$greg_month = $gregorian_from_fixed[1];
$greg_year = $gregorian_from_fixed[2];
$israelite_count = israelite_from_fixed($test_date);
$isr_cycle = $israelite_count[0];
$isr_year = $israelite_count[1];
$isr_month = $israelite_count[2];
$isr_day = $israelite_count[3];
$israelite_year = israelite_year_from_count($isr_cycle, $isr_year);
print "$greg_day $months[$greg_month] $greg_year | ";
print " = | ";
print " $isr_day $israelite_months[$isr_month], $israelite_year | ";
print "What goes here to make holidays? | ";
print "
";
}
print "
";
print "
-------------------------------------------------------";
html_end ();
#----------------------------------------------------------------------
[/php]
I want to add code to pull from a list of holidays (fixed) that can correspond to the $isr_month and $isr_day of a given date. I just don't know how to do this. If I can avoid SQL, I'd prefer it.
Here are the INC files referenced:
gregorian.inc
[php]
<?php
$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December', 'Leap Week');
$short_months = array (1 => 'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
function gregorian_leap_year($g_year)
{
$gregorian_leap_year = FALSE;
if (($g_year % 4 == 0) && ($g_year % 400 != 100 && $g_year % 400 != 200 && $g_year % 400 != 300))
{
$gregorian_leap_year = TRUE;
}
return $gregorian_leap_year;
}
function fixed_from_gregorian($g_year, $g_month, $g_day)
{
$fixed_date = 365 * ($g_year - 1);
$fixed_date += FLOOR(($g_year - 1) / 4) - FLOOR(($g_year - 1) / 100) + FLOOR(($g_year - 1) / 400);
$fixed_date += FLOOR((367 * $g_month - 362) / 12);
if ($g_month > 2)
{
if (gregorian_leap_year($g_year))
{
$fixed_date -= 1;
}
else
{
$fixed_date -= 2;
}
}
$fixed_date += $g_day;
return $fixed_date;
}
function gregorian_new_year($g_year)
{
$gregorian_new_year = fixed_from_gregorian($g_year, 1, 1);
return $gregorian_new_year;
}
function gregorian_year_end($g_year)
{
$gregorian_year_end = fixed_from_gregorian($g_year, 12, 31);
return $gregorian_year_end;
}
function gregorian_year_from_fixed($fixed_date)
{
$d0 = $fixed_date - 1;
$n400 = FLOOR($d0 / 146097);
$d1 = $d0 % 146097;
$n100 = FLOOR($d1 / 36524);
$d2 = $d1 % 36524;
$n4 = FLOOR($d2 / 1461);
$d3 = $d2 % 1461;
$n1 = FLOOR($d3 / 365);
if (($n100 == 4) || ($n1 == 4))
{
$gregorian_year_from_fixed = 400 * $n400 + 100 * $n100 + 4 * $n4 + $n1;
}
else
{
$gregorian_year_from_fixed = 400 * $n400 + 100 * $n100 + 4 * $n4 + $n1 + 1;
}
return $gregorian_year_from_fixed;
}
function gregorian_from_fixed($fixed_date)
{
$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December');
$g_year = gregorian_year_from_fixed($fixed_date);
$prior_days = $fixed_date - gregorian_new_year($g_year);
$march1 = fixed_from_gregorian($g_year, 3, 1);
$leap_year = gregorian_leap_year($g_year);
if ($fixed_date < $march1)
{
$correction = 0;
}
else if ($leap_year)
{
$correction = 1;
}
else
{
$correction = 2;
}
$g_month = FLOOR((12 * ($prior_days + $correction) + 373) / 367);
$day1 = fixed_from_gregorian($g_year, $g_month, 1);
$g_day = 1 + $fixed_date - $day1;
$gregorian_from_fixed = array ($g_day, $g_month, $g_year);
return $gregorian_from_fixed;
}
?>
[/php]
common.inc
[php]
<?php
$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December', 'Leap Week');
$sunday = 0;
# Index constants for locale
$latitude = 0;
$longitude = 1;
$elevation = 2;
$zone = 3;
$jd_epoch = -1721424.5;
function signum($x) {
if ($x < 0) {
$y = -1;
} else if ($x == 0) {
$y = 0;
} else {
$y = 1;
}
return $y;
}
function amod($x, $y)
{
if ($x % $y == 0)
{
$result = $y;
}
else
{
$result = $x % $y;
}
return $result;
}
function moment_from_jd($jd) {
global $jd_epoch;
$moment_from_jd = $jd + $jd_epoch;
return $moment_from_jd;
}
function fixed_from_jd($jd) {
$fixed_from_jd = floor(moment_from_jd($jd));
return $fixed_from_jd;
}
function nth_kday($n, $k, $g_date) {
if ($n > 0) {
$nth_kday = 7 * $n + kday_before($k, $g_date);
} else {
$nth_kday = 7 * $n + kday_after($k, $g_date);
}
return $nth_kday;
}
function kday_before($k, $date) {
$kday_before = kday_on_or_before($k, $date - 1);
return $kday_before;
}
function kday_after($k, $date) {
$kday_after = kday_on_or_before($k, $date + 7);
return $kday_after;
}
function kday_on_or_before($k, $date) {
$kday_on_or_before = $date - day_of_week_from_fixed($date - $k);
return $kday_on_or_before;
}
function day_of_week_from_fixed($date) {
$day_of_week = ($date - 0) % 7;
return $day_of_week;
}
?>
[/php]
html.inc
[php]
<?php
function html_begin ($title, $header)
{
print ("\n");
print ("\n");
if ($title != "")
print ("$title\n");
print ("");
print ("\n");
# print ("");
print ("");
print ("
");
print ("
");
}
function html_end ()
{
// print ("� Time Meddler $x_year
");
print ("");
print ("");
}
?>
[/php]
orecha.inc
[php]
<?php
$days_in_era = 121991;
$days_in_cycle = array ( 1=> 6940, 6940, 6939);
$days_in_year = array ( 1=> 384, 354, 354, 384, 354, 355, 384, 354, 355, 384,
354, 384, 354, 355, 384, 354, 355, 384, 354);
$days_in_month = array ( 1=> 30, 29, 30, 29, 30, 29, 30, 29, 30, 29, 30, 29, 30);
$israelite_months = array ( 1=> 'Yeraḥ ʼĀḇīḇ', 'Yeraḥ Zīw', 'Yeraḥ ʼĂp̄īlaṯ', 'Yeraḥ Marəpēʼ', 'Yeraḥ Ṣaḥ', 'Yeraḥ Pəḡārīm',
'Yeraḥ ʼĒṯānīm', 'Yeraḥ Būl', 'Yeraḥ Qōreṯ', 'Yeraḥ Zeḇaḥ Šemeš', 'Yeraḥ Ḥūrī', 'Yeraḥ Gīḇəʻōl', 'Yeraḥ Mēp̄āʻaṯ');
$israelite_epoch = fixed_from_gregorian(-1475, 3, 30);
function israelite_day_number($date) {
global $israelite_epoch;
$israelite_day_number = $date - $israelite_epoch + 1;
return $israelite_day_number;
}
function israelite_from_fixed($date) {
global $prior_days, $days_in_era, $days_in_cycle, $days_in_year, $days_in_month;
// Calculate eras elapsed and days elapsed in current era
// An era is one "grand cycle" of 17 19-year cycles and one 11-year cycle,
// a total of 121,991 days, or 1 less in every 6th and 13th era
$era_count = 0;
$days_remaining = israelite_day_number($date);
while ($days_remaining > 0) {
$era_count++;
if ($era_count % 6 == 0) {
$days_in_era = 121990;
} elseif ($era_count % 13 == 0) {
$days_in_era = 121990;
} else {
$days_in_era = 121991;
}
$days_elapsed_in_era = $days_remaining;
$days_remaining -= $days_in_era;
}
$days_remaining = $days_elapsed_in_era;
$era_count--;
// Calculate cycles elapsed and days elapsed in current cycle
$cycle_count = $era_count * 18 + 1;
while ($days_remaining > 0) {
$days_elapsed_in_cycle = $days_remaining;
$cycle_index = $cycle_count % 3;
if ($cycle_index == 0) {$cycle_index = 3;}
$days_remaining -= $days_in_cycle[$cycle_index];
$cycle_count++;
}
$days_remaining = $days_elapsed_in_cycle;
$cycle_count--;
// Calculate years elapsed in current cycle and days elapsed in current year
$year_count = 1;
if ($cycle_count % 3 == 3) {
$days_in_year[19] = 354;
}
while ($days_remaining > 0) {
$days_elapsed_in_year = $days_remaining;
$days_remaining -= $days_in_year[$year_count];
$year_count++;
}
$days_remaining = $days_elapsed_in_year;
$year_count -= 1;
// Calculate months elapsed in current year and days elapsed in current month
$month_count = 1;
if ($cycle_count % 3 == 3) {
if (($year_count == 6) || ($year_count == 9) || ($year_count == 14)) {
$days_in_month[6] = 30;
} else {
$days_in_month[6] = 29;
}
} elseif ($cycle_count % 18 == 0) {
if (($year_count == 6) || ($year_count == 9)) {
$days_in_month[6] = 30;
} else {
$days_in_month[6] = 29;
}
} else {
if (($year_count == 6) || ($year_count == 9) || ($year_count == 14) || ($year_count == 17)) {
$days_in_month[6] = 30;
} else {
$days_in_month[6] = 29;
}
}
while ($days_remaining > 0) {
$days_elapsed_in_month = $days_remaining;
$days_remaining -= $days_in_month[$month_count];
$month_count++;
}
$days_remaining = $days_elapsed_in_month;
$month_count -= 1;
$day_count = $days_elapsed_in_month;
$israelite_count = array ($cycle_count, $year_count, $month_count, $day_count);
return $israelite_count;
}
function israelite_year_from_count($cycle_count, $year_count) {
$israelite_era = ceil($cycle_count / 18);
$cycles = $cycle_count - ($israelite_era - 1) * 18;
$israelite_year = (($israelite_era - 1) * 334) + ($cycles - 1) * 19 + $year_count;
return $israelite_year;
}
?>
[/php]
Thank you for any help you can provide! I’m a poor anthropologist working independently (for free, I might add) for the advancement of cultural understanding.