<HTML><HEAD>
<TITLE> Julian date in php testing </TITLE>
</HEAD><BODY>

<?php

include_once("CalDate.inc");

$TS=time();

$UTInstantNow['YEAR'] = gmdate("Y", $TS);
$UTInstantNow['MONTH'] = gmdate("m", $TS);
$UTInstantNow['DAY'] = gmdate("d", $TS);
$UTInstantNow['HOUR'] = gmdate("H", $TS);
$UTInstantNow['MINUTE'] = gmdate("i", $TS);
$UTInstantNow['SECOND'] = gmdate("s", $TS);
$UTInstantNow['J_DATE'] = 0.0;
$UTInstantNow['D_HOUR'] = 0.0;
$UTInstantNow['D_MINUTE'] = 0.0;
$UTInstantNow['WEEKDAY'] = 0;
$UTInstantNow['DAY_OF_YEAR'] = 0;
$JD=JulDate(&$UTInstantNow);
$D=FormatCalDate($UTInstantNow);

printf("<TABLE><TR><TD ALIGN=CENTER>\n");
printf("The time now is: %s UT = JD: %.6f<BR>\n", $D, $JD );
printf("</TD></TR><TR><TD ALIGN=CENTER>\n");

printf("To exercise the calculator, you can enter a calendar date\n");
printf("and ask for <BR> a julian date to be calculated.  Or enter a julian\n");
printf("date <BR> and ask for a calendar date to be calculated.\n");

printf("</TD></TR><TR><TD ALIGN=CENTER>\n");

if( isset($HTTP_POST_VARS["J_DATE"]) ) {
	$UTInstantNow['J_DATE'] = $HTTP_POST_VARS["J_DATE"];
	$Y = CalDate(&$UTInstantNow);
	$JD = $UTInstantNow['J_DATE'];
} else {

	if( isset($HTTP_POST_VARS["YEAR"]) ) {
		$UTInstantNow['YEAR'] = (int)$HTTP_POST_VARS["YEAR"];
	} else {
		$UTInstantNow['YEAR'] = gmdate("Y", $TS);
	}
	if( isset($HTTP_POST_VARS["MONTH"]) ) {
		$UTInstantNow['MONTH'] = (int)$HTTP_POST_VARS["MONTH"];
	} else {
		$UTInstantNow['MONTH'] = gmdate("m", $TS);
	}
	if( isset($HTTP_POST_VARS["DAY"]) ) {
		$UTInstantNow['DAY'] = (int)$HTTP_POST_VARS["DAY"];
	} else {
		$UTInstantNow['DAY'] = gmdate("d", $TS);
	}
	if( isset($HTTP_POST_VARS["HOUR"]) ) {
		$UTInstantNow['HOUR'] = (int)$HTTP_POST_VARS["HOUR"];
	} else {
		$UTInstantNow['HOUR'] = gmdate("H", $TS);
	}
	if( isset($HTTP_POST_VARS["MINUTE"]) ) {
		$UTInstantNow['MINUTE'] = (int)$HTTP_POST_VARS["MINUTE"];
	} else {
		$UTInstantNow['MINUTE'] = gmdate("i", $TS);
	}
	if( isset($HTTP_POST_VARS["SECOND"]) ) {
		$UTInstantNow['SECOND'] = (int)$HTTP_POST_VARS["SECOND"];
	} else {
		$UTInstantNow['SECOND'] = gmdate("s", $TS);
	}
	$UTInstantNow['J_DATE'] = 0.0;
	$UTInstantNow['D_HOUR'] = 0.0;
	$UTInstantNow['D_MINUTE'] = 0.0;
	$UTInstantNow['WEEKDAY'] = 0;
	$UTInstantNow['DAY_OF_YEAR'] = 0;

	$JD=JulDate(&$UTInstantNow);
	$Y = CalDate(&$UTInstantNow);	# forces valid date
}

$D=FormatCalDate($UTInstantNow);

printf("</TD></TR><TR><TD ALIGN=CENTER>\n");

if( isset($HTTP_POST_VARS["J_DATE"]) ) {
	printf("<TABLE BORDER=1><TR><TH COLSPAN=2> Calculated Calendar<BR>Date </TH>\n");
	printf("<TH> %s </TH><TH> From JD:<BR>%.6f </TH></TR><TR><TD>\n", $D, $JD);
} else {
	printf("<TABLE BORDER=1><TR><TH COLSPAN=2> Given Calendar Date </TH>\n");
	printf("<TH COLSPAN=2> %s </TH></TR><TR><TD>\n", $D);
}
print '<FORM ACTION="Jday.php"';
print 'METHOD=POST>';
printf("YEAR: <INPUT TYPE=\"text\" SIZE=10 NAME=YEAR VALUE=\"%-d\">", $UTInstantNow['YEAR']);
print '&nbsp;';
print '</TD><TD>';
print 'MONTH: <SELECT NAME=MONTH>';
for( $i = 1; $i < 13; $i++ )
	if ( $i == $UTInstantNow['MONTH'] ) {
		printf("<OPTION SELECTED> %02d", $UTInstantNow['MONTH'] );
	} else {
		printf("<OPTION> %02d\n", $i);
	}
print '</SELECT>';
print '&nbsp;';
print '</TD><TD>';
print 'DAY: <SELECT NAME=DAY>';
for( $i = 1; $i < 32; $i++ )
	if ( $i == $UTInstantNow['DAY'] ) {
		printf("<OPTION SELECTED> %02d", $UTInstantNow['DAY'] );
	} else {
		printf("<OPTION> %02d\n", $i);
	}
print '</SELECT>';
print '</TD><TD>';
print '<INPUT TYPE=SUBMIT VALUE="Calculate Julian Date">';
print '</TD></TR><TR><TD>';
print '<BR>';
print 'HOUR: <SELECT NAME=HOUR>';
for( $i = 0; $i < 24; $i++ )
	if ( $i == $UTInstantNow['HOUR'] ) {
		printf("<OPTION SELECTED> %02d", $UTInstantNow['HOUR'] );
	} else {
		printf("<OPTION> %02d\n", $i);
	}
print '</SELECT>';
print '&nbsp;';
print '</TD><TD>';
print 'MINUTE: <SELECT NAME=MINUTE>';
for( $i = 0; $i < 60; $i++ )
	if ( $i == $UTInstantNow['MINUTE'] ) {
		printf("<OPTION SELECTED> %02d", $UTInstantNow['MINUTE'] );
	} else {
		printf("<OPTION> %02d\n", $i);
	}
print '</SELECT>';
print '&nbsp;';
print '</TD><TD>';
print 'SECOND: <SELECT NAME=SECOND>';
for( $i = 0; $i < 61; $i++ )
	if ( $i == (int)($UTInstantNow['SECOND'] + 0.5) ) {
		printf("<OPTION SELECTED> %02d", (int)($UTInstantNow['SECOND'] + 0.5) );
	} else {
		printf("<OPTION> %02d\n", $i);
	}
print '</SELECT><BR>';
print '</FORM>';
print '</TD></TR></TABLE>';

printf("</TD></TR><TR><TD ALIGN=CENTER>\n");

if( isset($HTTP_POST_VARS["J_DATE"]) ) {
	printf("<TABLE BORDER=1><TR><TH> Given Julian Date </TH>\n");
	printf("<TH> %.6f </TH></TR><TR><TD>\n", $JD);
} else {
	printf("<TABLE BORDER=1><TR><TH> Calculated Julian Date<BR> %.6f </TH>\n", $JD);
	printf("<TH> From: $D </TH></TR><TR><TD>\n");
}

print '<FORM ACTION="Jday.php"';
print 'METHOD=POST>';
printf("JD: <INPUT TYPE=\"text\" SIZE=20 NAME=J_DATE VALUE=\"%.6f\">", $UTInstantNow['J_DATE']);
printf("</TD><TD>\n");
print '<INPUT TYPE=SUBMIT VALUE="Calculate Calendar Date">';
print '</FORM>';

print '</TD></TR></TABLE>';

printf("</TD></TR><TR><TD ALIGN=CENTER>\n");

print '<FORM ACTION="Jday.php"';
print 'METHOD=POST>';
print '<INPUT TYPE=SUBMIT VALUE="Reset form to today">';
print '</FORM>';

printf("</TD></TR><TR><TD ALIGN=CENTER>\n");

printf("Your inputs will not be verified to be a valid date.<BR>\n");
printf("However, your input will become a valid date as it is calculated.<BR>\n");
printf("For example, you can ask for a February 29 of a non-leap year<BR>\n");
printf("and it will become March 01.<BR><BR>\n");
printf("The valid lower limit for a date is -4171/01/01 12:00:00 = JD: 0.0<BR>\n");
printf("The upper limit for year and julian day number will depend <BR>\n");
printf("upon the size of an integer for the PHP implementation <BR>\n");
printf("on the WEB server system.  A 32 bit machine has an upper limit<BR>\n");
printf("of 5879490/02/28 23:59:59 -> JD: 2149160745.499989 <BR>\n");
printf("or: JD: 2147438064.499988 ->  5874773/08/15 23:59:59 <BR>\n");
printf("(that is an interesting little difference !  Needs to be checked<BR>\n");
printf("on a 64 bit machine)\n");
print '</TD></TR></TABLE>';

?>

</BODY></HTML>
