Jump to content

Lunisolar Calendar -- Help Needed


Recommended Posts

Hello.

A bit of warning up front: I'm an anthropologist, not a programmer, so a great deal of this goes right over my head!

 

I've been working for a couple of years now on reconstructing an Iron Age I Canaanite calendar. The math is done, and thanks to the assistance of Alex over at timemeddler.co.uk, a great deal of the code is done as well. I've hit a bit of a snag, however. While the code I have prints a nice, neat table with Gregorian dates on the left and Canaanite/Israelite dates on the right, there are a couple of extra things I'd like it to do that I just can't figure out.

 

1. I desperately need the column which currently says "What goes here to make holidays?" to actually have holidays in it. I have no idea how to do this. I'd love for it to be hard coded, as the holidays are fixed and I'd rather not go through SQL databases. They would need to correspond to specific Canaanite/Israelite dates, probably utilizing the $isr_month and $isr_day. I'd love it if the list of holidays was built into orecha.inc so that it was usable elsewhere. I know this is possible, I just have NO idea how to get it to work, primarily due to a lack of experience with PHP.

 

2. I'd love to have the table print as a calendar format, with each Gregorian month separate and the Israelite/Canaanite dates and holidays contained withing the individual cells, like events. I'm sure that's a bit more complex, so it's not necessary, but strongly wanted.

 

 

Here's my primary PHP and the relevant INC files:

 

OQ_Calendar.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 "<br><b>$test_year</b>";

$start_date = fixed_from_gregorian($test_year, 1, 1);
$end_date = fixed_from_gregorian($test_year, 12, 31);

print "<table width=710 border=0>";
for ($test_date = $start_date; $test_date <= $end_date; $test_date++) {
	print "<tr>";
	$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 "<td width=140 align=right>$greg_day $months[$greg_month] $greg_year</td>";
	print "<td width=60 align=center> = </td>";
	print "<td width=200 align=left> $isr_day <i>$israelite_months[$isr_month]</i>, $israelite_year</td>";
	print "<td width=200 align=left>What goes here to make holidays?</td>";
	print "</tr>";

}
print "</table>";
print "<br>-------------------------------------------------------";


html_end ();

#----------------------------------------------------------------------

gregorian.inc

<?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;
}

?>

orecha.inc

<?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;
}


?>

html.inc

<?php
function html_begin ($title, $header)
{
	print ("<html>\n");
	print ("<head>\n");
	if ($title != "")
		print ("<title>$title</title>\n");
	print ("<LINK REL=stylesheet TYPE='text/css' HREF='mystyle.css'>");
	print ("</head>\n");
#	print ("<BODY bgcolor='#2D6840'>");
	print ("<BODY bgcolor='#CCCCFF'>");
	print ("<div id='main' class='main'>");
	print ("<table width='600' cellpadding='5'>");
}

function html_end ()
{
//	print ("<p><i>� Time Meddler $x_year</i></p>");
	print ("</div>");
	print ("</body></html>");
}

?>

common.inc

<?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;
}


?>

Thank you for any assistance you can provide a poor coding-inept anthropologist!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.