Discordian date: Difference between revisions

Line 2,229:
 
=={{header|PHP}}==
{{incorrect|PHP|With a user-defined date, the season is always Chaos, and in the year 2000 nothing works except St. Tib's Day.}}
 
<lang PHP><?php
// Discordian dating machine. Accepts date from PHP function date() or from the URL.
// The Discordian calendar has 5 days in a week, 73 days in a month and 5 months in a year.
// Ex. ddate.php will generate todays date according to your computer
// Ex. ddate.php?y=2012&m=2&y=29 will generate the date for Feb. 29, 2012
 
<lang PHP>
$DAYS = array("Sweetmorn","Boomtime","Pungenday","Prickle-Prickle","Setting Orange");
<?php
$MONTHS = array("Chaos","Discord","Confusion","Bureaucracy","The Aftermath");
$Anerisia = array(31,28,31,30,31,30,31,31,30,31,30,31);
$MONTHS = array("Choas","Discord","Confusion","Bureacracy","The Aftermath");
$DAYS = array("Setting Orange","Sweetmorn","BoomTime","Pungenday","Prickle-Prickle");
$Dsuff = array('th','st','nd','rd','th','th','th','th','th','th');
$Holy5 = array("Mungday","MojoDay","Syaday","Zaraday","Maladay");
$Holy50 = array("Chaoflux","Discoflux","Confuflux","Bureflux","Afflux");
 
// If user passed year, month and day variables in URL
if(isset($_GET['y']) && isset($_GET['m']) && isset($_GET['d'])) {
// Get year, month and day from URL
$usery = $_GET['y']; $userm = $_GET['m']; $userd = $_GET['d'];
// Use unix time to calculate day of year starting at zero
$userdate = mktime(0,0,0,$userm,$userd,$usery);
$ddays = ($userdate - mktime(0,0,0,1,1,$usery)) / 86400;
// Calculates the Discordian year, month and day
$dyear = ($usery) + 1166; $dmonth = $MONTHS[$dday/73]; $dday = $ddays%73 + 1;
}
// If user didn't pass year, get date from PHP function
else {
// Create array containing current Gregorian year, month, day,
// days of year starting at zero and whether or not year is a leap
$date = explode(" ",date('Y n j z L'));
// Calculates the Discordian year, month and day
$dyear = $date[0]+1166; $dmonth = $MONTHS[$date[3]/73]; $dday = $date[3]%73 +1;
}
// Determine the name of the day
if ($ddays === NULL) { $ddayname= $DAYS[$date[3]%5]; }
else { $ddayname= $DAYS[$ddays%5]; }
 
// Leap year exception for date from PHP
 
if ($ddays === NULL) {
// Get the current system date and assign to some variables
if ($date[4]) {
$edate = explode(" ",date('Y m j L'));
if ($date[1] == 2 && $date[2] == 29) { echo "Today is St. Tib's Day, YOLD " . $dyear; }
$usery = $edate[0];
if ($date[3] >= 60) { //offset day by one if leap year
$ddayuserm -= $edate[1];
$userd = $edate[2];
if($dday % 5 == 0) $ddayname = $DAYS[4];
else $ddaynameIsLeap = $DAYSedate[($dday%5)3];
 
}
// If the user supplied us with a date overide the one we got from the system.
}
// If you could get the date from users browser via javascript and then call
// Display Discordian date
// this script with the users date. ddate.php?y=year&m=month&d=day mostly it
echo "Today is " . $ddayname . ", " . $dmonth . " " . $dday . ", YOLD " . $dyear;
// won't matter but if the server is in a different time zone to the user
}
// There will be occasional incorrect results from the users POV.
else { // Leap year exception for date from URL
 
if ($usery % 100 == 0) { // leap year exception for years that are divisible by one hundred
if (isset($_GET['y']) && isset($_GET['m']) && isset($_GET['d'])) {
if ($usery % 400 == 0 && $userm == 2 && $userd == 29) { echo "Today is St. Tib's Day, YOLD " . $dyear; }
$usery = $_GET['y'];
}
$userm = $_GET['m'];
else if ($usery % 4 == 0) { // if the year is a leap year
$userd = $_GET['d'];
if ($userm == 2 && $userd == 29) { echo "Today is St. Tib's Day, YOLD " . $dyear; }
$IsLeap = 0;
elseif ($ddays >= 60) { // offset day by one if leap year
if (($usery%4 == 0) && ($usery%100 >0)) $IsLeap =1;
$dday -=1;
if ($dday usery% 5400 == 0) $ddaynameIsLeap = $DAYS[4]1;
}
else $ddayname=$DAYS[($dday%5-1)];
 
echo "Today is " . $ddayname . ", " . $dmonth . " " . $dday . ", YOLD " . $dyear;
// We need to know the total number of days in the year so far
}
 
else { echo "Today is " . $ddayname . ", " . $dmonth . " " . $dday . ", YOLD " . $dyear; }
$userdays = 0;
}
$i = 0;
// Display Discordian date
while ($i < ($userm-1)) {
else { echo "Today is " . $ddayname . ", " . $dmonth . " " . $dday . ", YOLD " . $dyear; }
}
$userdays = $userdays + $Anerisia[$i];
?>
$i = $i +1;
}
$userdays = $userdays + $userd;
 
// We can now work out the full discordian date for most dates
// PHP does not do integer division, so we use 73.2 as a divisor
// the value 73.2 works, larger values cause an off-by-one on season
// changes for the later seasons .
// This is not needed with the mod operator.
 
$IsHolyday = 0;
$dyear = $usery + 1166;
$dmonth = $MONTHS[$userdays/73.2];
$dday = $userdays%73;
if (0 == $dday) $dday = 73;
$Dname = $DAYS[$userdays%5];
$Holyday = "St. Tibs Day";
if ($dday == 5) {
$Holyday = $Holy5[$userdays/73.2];
$IsHolyday =1;
}
if ($dday == 50) {
$Holyday = $Holy50[$userdays/73.2];
$IsHolyday =1;
}
 
if (($IsLeap ==1) && ($userd ==29) and ($userm ==2)) $IsHolyday = 2;
 
// work out the suffix to the day number
$suff = $Dsuff[$dday%10] ;
if ((11 <= $dday) && (19 >= $dday)) $suff='th';
 
// code to display the date ...
 
if ($IsHolyday ==2)
echo "</br>Celeberate ",$Holyday," ",$dmonth," YOLD ",$dyear;
if ($IsHolyday ==1)
echo "</br>Celeberate for today ", $Dname , " The ", $dday,"<sup>",$suff,"</sup>", " day of ", $dmonth , " YOLD " , $dyear , " is the holy day of " , $Holyday;
if ($IsHolyday == 0)
echo "</br>Today is " , $Dname , " the " , $dday ,"<sup>",$suff, "</sup> day of " , $dmonth , " YOLD " , $dyear;
 
?>
</lang>
 
{{Out}}
<pre>ddate.php #23 November 2011
Today is Boomtime, the 35th day of The Aftermath 35, YOLD 3177
 
ddate.php?y=2012&m=2&y=28
Today is Prickle-Prickle, Chaosthe 59,59th day of Chaos YOLD 3178
 
ddate.php?y=2012&m=2&y=29
Today isCeleberate St. Tib'sTibs Day, Chaos YOLD 3178
 
ddate.php?y=20122017&m=38&yd=112
Celeberate for today Prickle-Prickle The 5th day of Bureacracy YOLD 3183 is the holy day of Zaraday
Today is Setting Orange, Chaos 60, YOLD 3178
</pre>
 
Anonymous user