<?
/**************************************************************************
**
** PHP class dutchclock
** This class is made is a learning aid for foreign students learning
** the Dutch language.
**
** Programmed and donated to the public domain
** by Rene Kluwen <hide@address.com>.
**
** Note: Times in strings are rounded off by 5 minutes for clarity.
**
** Example usage:
**
** $clock = new dutchclock(date("h:i"));
** echo "Huidige tijd (current time) is: " . $clock->dutchtime();
**
***************************************************************************/
class dutchclock {
var $_hours;
var $_minutes;
function dutchclock($time) {
// given a time in hh:mm military time format
preg_match("/(\\d\\d):(\\d\\d)/", $time, $matches);
$this->_hours = $matches[1];
$this->_minutes = $matches[2] % 60;
}
function show() {
// shows an analog clock in swf format
// not more than a gadget
$movie = new SWFMovie();
$movie->SetRate(1.0);
$movie->setDimension(150, 160);
// bitmap holds a picture of a clock
$bitmap = new SWFBitmap(fopen("http://www.chimit.nl/dutchclock/clock.jpg", "rb"));
$movie->add($bitmap);
// little is the small pointer
$little = new SWFShape();
$little->setLine(3, 0x7f, 0, 0);
$little->movePenTo(0, 0);
$little->drawLineTo(0, -25);
$ls = $movie->add($little);
$ls->moveTo(75, 75);
$hours = $this->_hours % 12 + (($this->_minutes / 60));
$ls->rotateTo((($hours / 12) * -360));
// big holds the big pointer
$big = new SWFShape();
$big->setLine(2, 0x7f, 0, 0);
$big->movePenTo(0, 0);
$big->drawLineTo(0, -40);
$bs = $movie->add($big);
$bs->moveTo(75, 75);
$bs->rotateTo((($this->_minutes / 60) * -360));
Header('Content-type: application/x-shockwave-flash');
$movie->output();
}
function number($num) {
$nums = array("", "een", "twee", "drie", "vier", "vijf", "zes", "zeven", "acht", "negen", "tien", "elf", "twaalf");
return $nums[$num];
}
function dutchtime() {
$res = "";
// round minutes up/down to 5
$rminutes = round($this->_minutes / 5) * 5;
$modminutes = $rminutes % 15;
// Dutchies are interested in a 12 hour clock
if (($this->_hours == 12) || ($this->_hours == 0))
$rhours = 12;
else
$rhours = $this->_hours % 12;
// add becomes one after 30 or more minutes after an hour
$add = 0;
// determine which quadrant we are
// word: one of (empty), over, over half, voor, voor half
switch (IntVal(($rminutes - 1) / 15)) {
case 0:
$word = "over";
break;
case 1:
$add = 1;
$modminutes = 15 - $modminutes;
$word = "voor half";
break;
case 2:
$add = 1;
$word = "over half";
break;
case 3:
$add = 1;
$modminutes = 15 - $modminutes;
$word = "voor";
break;
}
// set the following variables:
// preword: one of (empty), kwart, half, [number]
// postword: one of (empty), uur
// whole hours, half hours and quarters are exeptions
switch ($rminutes % 60) {
case 0:
$preword = "";
$word = "";
$postword = "uur";
break;
case 15:
$preword = "kwart";
$word = "over";
$postword = "";
break;
case 30:
$preword = "half";
$word = "";
$postword = "";
break;
case 45:
$preword = "kwart";
$word = "voor";
$postword = "";
break;
default:
$preword = $this->number($modminutes);
$postword = "";
break;
}
// rhours is the hour that appears in the sentence.
// It can be one more than the hour, given in the time string.
$rhours = ($rhours + $add) % 12;
if ($rhours == 0) $rhours = 12;
// whours is rhours in text format
$whours = $this->number($rhours);
// aptext is text to append: one off in de ochtend, in de middag, in de avond
if ((($this->_hours) % 24) < 12)
$aptext = "in de ochtend";
elseif (($this->_hours) < 18)
$aptext = "in de middag";
else
$aptext = "in de avond";
// and the result string is made of a simple concatenation.
$res = "$preword $word $whours $postword ($aptext)";
return $res;
}
}
?>