Sunday, November 22, 2009

Tech Note: Calender fix got to get fixed

So I'm no something of a calender fix, don't ask me why that's just how I role. And thus here's some code for an xhtml calendar, php-gened + with a custom start and a custom end:


$start=array(4,19,1986);
$day = 24*60*60;
$ts = mktime(0,0,0,$start[0],$start[1],$start[2]);
$ts -= date('w',$ts)*$day;
$doctype = DOMImplementation::createDocumentType("html",
"-//W3C//DTD XHTML 1.0 Strict//EN",
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd");
$doc = DOMImplementation::createDocument(null, 'html', $doctype);
$html=$doc->documentElement;
$head=$doc->createElement('head');
$head->appendChild($doc->createElement('title','Timeline'));
$style = $doc->createElement('style');
$style->setAttribute('type','text/css');
$styledata = '
table {
width: 100%;
}
table td {
width: 12%;
}
';
$style->appendChild($doc->createCDATASection($styledata));
$head->appendChild($style);
$html->appendChild($head);
$body=$doc->createElement('body');
$html->appendChild($body);

$table=$doc->createElement('table');
$body->appendChild($table);
$thead=$doc->createElement('thead');
$table->appendChild($thead);
$trow=$doc->createElement('tr');
$thead->appendChild($trow);
$trow->appendChild($doc->createElement('th','Sunday'));
$trow->appendChild($doc->createElement('th','Monday'));
$trow->appendChild($doc->createElement('th','Tuesday'));
$trow->appendChild($doc->createElement('th','Wednesday'));
$trow->appendChild($doc->createElement('th','Thursday'));
$trow->appendChild($doc->createElement('th','Friday'));
$trow->appendChild($doc->createElement('th','Saturday'));
$endtime=mktime();
$tbody = $doc->createElement('tbody');
$table->appendChild($tbody);
$trow=$doc->createElement('tr');
$td=$doc->createElement('td');
$h2=$doc->createElement('h2',date('F Y',$ts));
$td->appendChild($h2);
$td->setAttribute('colspan','7');
$trow->appendChild($td);
$tbody->appendChild($trow);
while($ts < $endtime) {
$trow=$doc->createElement('tr');
for($i=0; $i < 7; $i++) {
$td=$doc->createElement('td');
$td->appendChild($doc->createElement('h3',date('d',$ts)));
$trow->appendChild($td);
$pastday=$ts;
$ts+=$day;
if(date('d',$ts) $tbody->appendChild($trow);
$trow=$doc->createElement('tr');
$td=$doc->createElement('td');
$h2=$doc->createElement('h2',date('F Y',$ts));
$td->appendChild($h2);
$td->setAttribute('colspan','7');
$trow->appendChild($td);
$tbody->appendChild($trow);
$trow=$doc->createElement('tr');
for($j=0; $j < date('w',$ts);$j++) {
$td=$doc->createElement('td');
$trow->appendChild($td);
}
}
}
$tbody->appendChild($trow);
}
header('Content-Type: text/xml');
echo $doc->saveXML();
exit();


Is that the only way to do things?

No.

Is that the best way to do things?

Honestly probably not.

What would probably be the best is if I could bust out some awesome XPath and XSL 2.0 functions/elements - with the date-time/duration functions this would be trivial, so much so it would not make it to any trivia gameshow of any repute.

However, as your next trivia question - who's fighting this lameness - XQilla! Qilla on, dude, Qilla on.

So take it to your head, take it to your heart and remember Rand rocks. Goodnight Folks!

And God Bless.

2 comments:

Anonymous said...

[URL=http://casino-dealer.co.cc/link/casino%20online/2_casinoss.html][IMG]http://casino-dealer.co.cc/img/casino%20online/2_casinoss.png[/IMG][/URL]

Anonymous said...

We sale online brand valium online. Purchase valium now! http://osdir.com/ml/scsi/2003-11/msg00063.html buy valium. The best quality.