Corrected code below:
Quote:
<?php
$day = date('d'); //today
$mercannum = $day / 6;
$base_year = -2; //for tweaking
if ($day >= 0 && $day < 1) { //saves extra years to be added into months below.
$extra_year = $base_year;
} else if ($day >= 6 && $day < 11) {
$extra_year = $base_year +1;
} else if ($day >= 11 && $day < 16) {
$extra_year = $base_year +2;
} else if ($day >= 16 && $day < 21) {
$extra_year = $base_year +3;
} else if ($day >= 21 && $day < 26) {
$extra_year = $base_year +4;
} else if ($day >= 26) {
$extra_year = $base_year +5; }
?><BR><?php
$date1 = '2009-01-01'; // 000 AI, although off by 37 on purpose (a needed fix, as starting at the beginning of the year makes all later calculations easier)
//$date2 = '2016-08-03'; Blank, used for testing
$date2 = date('Y-m-d'); //current date (full)
$ts1 = strtotime($date1); //convert string
$ts2 = strtotime($date2);
$year1 = date('Y', $ts1); //convert string year only
$year2 = date('Y', $ts2);
$month1 = date('m', $ts1); //convert string month only
$month2 = date('m', $ts2);
$month_diff = (($year2 - $year1) * 12) + ($month2 - $month1); //months between base and today
$canonyears_diff = $month_diff * 6;
$current_year = $canonyears_diff + $extra_year - 38;
?><strong><?php echo "Years of the Emperor: "; ?></strong><?php echo $current_year . " AI ";
$date3 = '2016-08-31'; // All of the below behaves like the above, but calculates cycles instead
$ts1 = strtotime($date3);
$ts2 = strtotime($date2);
$year1 = date('Y', $ts1);
$year2 = date('Y', $ts2);
$month1 = date('m', $ts1);
$month2 = date('m', $ts2);
$cycle_check_month_diff = (($year2 - $year1) * 12) + ($month2 - $month1);
//echo $month_diff;
$cycle_base = '2015-06-01';
$ts1 = strtotime($cycle_base);
$ts2 = strtotime($date2);
$year1 = date('Y', $ts1);
$year2 = date('Y', $ts2);
$month1 = date('m', $ts1);
$month2 = date('m', $ts2);
$cycle_month_diff = (($year2 - $year1) * 12) + ($month2 - $month1);
$cycle_merc = round($cycle_month_diff / 12);
$cycle_merc2 = $cycle_merc -1;
$cycle_year = $cycle_month_diff % 12;
$cycle_merc_padded = sprintf("%02d", $cycle_merc2);
$cycle_year_padded = sprintf("%02d", $cycle_year);
if ($cycle_check_month_diff > 1) {
?><strong><?php echo "| Cycle of the Tide: "; ?></strong><?php echo $cycle_merc_padded; ?><strong><?php echo "-"; ?></strong><?php echo $cycle_year_padded;
} else {
?><strong><?php echo "| Cycle of the Phoenix: "; ?></strong><?php echo $cycle_merc_padded; ?><strong><?php echo "-"; ?></strong><?php echo $cycle_year_padded;
}
?>
And the code for the calendar converter:
The below part loads external plugins and loads the calendar function. Place at the top of the page, such as above the <body>
Quote:
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<script>
$( function() {
$( "#datepicker" ).datepicker();
} );
</script>
This below part creates the clickable button (the text that needs to be clicked to expose the calendar). Easily modifiable. Just don't change the div name, id, or class names. Place whereever you want the calendar convert to sit.
Quote:
<div style="font-style: italic;" id="hide_calendar">Click to toggle calendar converter</div>
<div id="hidden_calendar">
<div id="calendar"></div>
<p>Converted Date: <input class="target" type="text" id="datepicker2" readonly></p>
</div>
And finally:
This is the code to make the calendar converter itself. It's usually easiest to put this at the very bottom of the page (but still inside the <body>).
Quote:
<script>
$( document ).ready(function() {
$("#hidden_calendar").hide();
});
$( ".target" ).change(function() {
//var value = this.value; // omit "var" to make it global
//var date1 = '07/31/2009';
//$(".target").text(value);
//alert( value );
});
$('#calendar').datepicker({
dateFormat: 'yy-m-d',
inline: true,
onSelect: function(dateText, inst) {
var date = $(this).datepicker('getDate'),
day = date.getDate(),
month2 = date.getMonth() + 1,
year2 = date.getFullYear();
var date1 = '7-31-2009';
var month1 = '7';
var year1 = '2009';
month_diff = ((year2 - year1) * 12) + (month2 - month1);
canonyears_diff = month_diff * 6;
base_year = -2;
if (day >= 0 && day < 6) {
extra_year = base_year;
} else if (day >= 6 && day < 11) {
extra_year = base_year +1;
} else if (day >= 11 && day < 16) {
extra_year = base_year +2;
} else if (day >= 16 && day < 21) {
extra_year = base_year +3;
} else if (day >= 21 && day < 26) {
extra_year = base_year +4;
} else if (day >=26) {
extra_year = base_year +5;
}
current_year = canonyears_diff + extra_year;
$('#datepicker2').val(current_year + ' AI');
}
});
$("#hide_calendar").click(function(){
$("#hidden_calendar").toggle();
});
</script>