PHP Classes

File: ddate.php

Recommend this page to a friend!
  Classes of Jurgen Schwietering   ddate   ddate.php   Download  
File: ddate.php
Role: ???
Content type: text/plain
Description: class for converting normal date to discordian date (ddate linux port)
Class: ddate
Author: By
Last change:
Date: 20 years ago
Size: 8,435 bytes


Class file image Download
<? /* $ DVCS ID: $jer|,523/lhos,KYTP!41023161\b"?" <<= DO NOT DELETE! */ /* ddate.c .. converts boring normal dates to fun Discordian Date -><- original incarnation written the 65th day of The Aftermath in the Year of Our Lady of Discord 3157 by Druel the Chaotic aka Jeremy Johnson aka Majorly hacked, extended and bogotified/debogotified on Sweetmorn, Bureaucracy 42, 3161 YOLD, by Lee H:. O:. Smith, KYTP, aka Andrew Bulhak, aka PHP class-version hack by vesel aka Jurgen Schwietering aka on Boomtime, Discord 14, 3168 YOLD usage: class constructor ddate($moe=0, $larry=0, $curly=0, $format=defFormat); (note: m d y format) getDDate(); // returns the datestring todayDdate(); // get the old immediate format echo "<BR>"; */ /* * @author: original c-code Jeremy Johnson, rewritten Jurgen Schwietering * @description-en: Create Discordian Date * @class: Date * @title: Create Discordian Date String */ class ddate{ /* configuration options VVVVV READ THIS!!! */ /* these are original formats, replace in ddate() if you would like to use them as default */ var $default_fmt = "%{%A, %B %d%}, %Y YOLD"; var $default_immediate_fmt="Today is %{%A, the %e day of %B%} in the YOLD %Y%N%nCelebrate %H"; /* PRAISE_BOB has been removed: JS */ var $day_long = array("Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle", "Setting Orange"); var $day_short = array("SM","BT","PD","PP","SO"); var $season_long = array("Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath"); var $season_short = array("Chs", "Dsc", "Cfn", "Bcy", "Afm"); var $holyday= array( array("Mungday", "Chaoflux"), array("Mojoday", "Discoflux"), array("Syaday", "Confuflux"), array("Zaraday", "Bureflux"), array("Maladay", "Afflux") ); var $excl =array( "Hail Eris!", "All Hail Discordia!", "Kallisti!", "Fnord.", "Or not.", "Wibble.", "Pzat!", "P'tang!", "Frink!", /* randomness, from the Net and other places. Feel free to add (after * checking with the relevant authorities, of course). */ "Hail Eris, Hack PHP!", "Grudnuk demand sustenance!", "Keep the Lasagna flying!", "Umlaut Zebra über alles!" ); var $schwa; // where to store the calculated date // private functions: function DY($y) { return $y+1166; } function ending($i) { return ($i%10==1)?"st":($i%10==2?"nd":($i%10==3?"rd":"th")); } function leapp($i) { return (!(DY($i)%4))&&((DY($i)%100)||(!(DY($i)%400))); } function format($fmt, $dt) { $wibble=""; $tib_start=-1; $tib_end=0; $fmtlen=strlen($fmt); // first, find extents of St. Tib's Day area, if defined for($i=0; $i<$fmtlen; $i++) { if($fmt{$i}=='%') { switch($fmt{$i+1}) { case 'A': case 'a': case 'd': case 'e': if($tib_start>0) $tib_end=$i+1; else $tib_start=$i; break; case '{': $tib_start=$i; break; case '}': $tib_end=$i+1; break; } } } // now do the formatting $buf=""; for($i=0; $i<$fmtlen; $i++) { if(($i==$tib_start) && ($dt["day"]==-1)) { /* handle St. Tib's Day */ $buf.="St. Tib's Day"; $i=$tib_end; } else { if($fmt[$i]=='%') { $i++; switch($fmt[$i]) { case 'A': $wibble=$this->day_long[$dt["yday"]%5]; break; case 'a': $wibble=$this->day_short[$dt["yday"]%5]; break; case 'B': $wibble=$this->season_long[$dt["season"]]; break; case 'b': $wibble=$this->season_short[$dt["season"]]; break; case 'd': $snarf=sprintf("%d", $dt["day"]+1); $wibble=$snarf; break; case 'e': $snarf=sprintf("%d%s", $dt["day"]+1, $this->ending($dt["day"]+1)); $wibble=$snarf; break; case 'H': if ($dt["day"]==4||$dt["day"]==49) $wibble = $this->holyday[$dt["season"]][$dt["day"]==49]; break; case 'N': if($dt["day"]!=4&&$dt["day"]!=49) return $buf; case 'n': $buf.='\n'; break; case 't': $buf.='\t'; break; case 'Y': $snarf=sprintf("%d", $dt["year"]); $wibble=$snarf; break; case '.': $wibble=$this->excl[rand(0,count($excl)-1)]; break; case '%': $wibble='%'; break; default: $wibble=""; // ignore break; } if($wibble) { $buf.=$wibble; } } else { $buf.=$fmt[$i]; } } } return $buf; } // I guess that in PHP we could make this much more short. JS function makeday($imonth,$iday,$iyear) /*i for input */ { $cal = array(31,28,31,30,31,30,31,31,30,31,30,31); $dayspast=0; $imonth--; $funkyChickens["year"]= $iyear+1166; while($imonth>0) { $dayspast+=$cal[--$imonth]; } $funkyChickens["day"]=$dayspast+$iday-1; $funkyChickens["season"]=0; if(($funkyChickens["year"]%4)==2) { if ($funkyChickens["day"]==59) $funkyChickens["day"]=-1; } $funkyChickens["yday"]=$funkyChickens["day"]; while($funkyChickens["day"]>=73) { $funkyChickens["season"]++; $funkyChickens["day"]-=73; } return $funkyChickens; } function convert($nday, $nyear) // returns assoc array [year,day,season,yday] { $funkyChickens["year"] = $nyear+3066; $funkyChickens["day"]=$nday; $funkyChickens["season"]=0; if (($funkyChickens["year"]%4)==2) {if ($funkyChickens["day"]==59) $funkyChickens["day"]=-1; else if ($funkyChickens["day"] >59) $funkyChickens["day"]-=1; } $funkyChickens["yday"]=$funkyChickens["day"]; while ($funkyChickens["day"]>=73){ $funkyChickens["season"]++; $funkyChickens["day"]-=73; } return $funkyChickens; } function ddate($moe=0, $larry=0, $curly=0, $format="%{%A, %B %d%}, %Y YOLD") { if ($moe==0) { $bob=date("z"); $raw=date("Y")-1900; $hastur=$this->convert($bob,$raw); } else $hastur=$this->makeday($larry, $moe, $curly); $this->schwa=$this->format($format, $hastur); return $this->schwa; } // public functions: function getDDate() { return $this->schwa; } // get the old ddate string for today function todayDdate($format="Today is %{%A, the %e day of %B%} in the YOLD %Y%N%nCelebrate %H") { $bob=date("z"); // eris->tm_yday; // days since Jan 1. $raw=date("Y")-1900; // eris->tm_year; // years since 1900 $hastur=$this->convert($bob,$raw); $this->schwa=$this->format($format, $hastur); return $this->schwa; } } // some short test $dd=new ddate(); echo $dd->getDDate(); echo "<BR>"; echo $dd->ddate(6,4,1964); // already created an object, so use it again. echo "<BR>"; echo $dd->todayDdate(); // the old immidiate format echo "<BR>"; ?>