====== qclock PHP ====== This is a quick port of the C commandline tool qclock. See http://www.nethack.net/qclock/ for the original. time(); /** * Quick port of http://www.nethack.net/qclock/ */ class qclock { var $greeting = array( "hi. ", "hello. ", "greetings. ", "salutations. ", "yo! ", "hey. ", "Segmentation fau--*cough*, er, i mean, " ); var $vague = array( " or something", " or thereabouts", ". i think. maybe", ". thank you, please drive through", ". and incidentally, can i interest you in these fine steak knives..", ", and dont blame me if i'm wrong", ". now go away, im plotting my world domination", ); var $preface = array( "current time: ", "the time is probably ", "the time is now ", "if you must know, the time is ", "and lo, ye olde tyme was thus: ", "it's " ); var $roman = array( "XII", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI" ); var $word = array( "twelve", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven" ); var $altword = array( "midnight", "one", "two", "too bloody early", "bloody early", "sparrow's fart", "sunrise", "breakfast time", "ate, er, i mean eight", "time to be at work", "ten", "time for a coffee break", "noon", "one", "two", "beer o'clock", "four", "knock-off time", "six", "food time", "eight", "nine", "ten", "eleven...it goes to eleven" ); function getword($n) { switch (rand(0,2)) { case 0: return $this->roman[$n % 12]; case 1: return $this->word[$n % 12]; case 2: return $this->altword[$n]; } } function nexthour($n){ return (($n<23)?($n+1):0); } function time() { $time = time(); $hours = (int) strftime('%I',$time); $mins = (int) strftime('%M',$time); $secs = (int) strftime('%S',$time); echo $this->greeting[array_rand($this->greeting)]; if (rand(0,4) == 0) { switch(rand(0,4)) { case 0: if ($hours < 6) printf("its too sodding early, go away.\n"); else if ($hours < 12) printf("its morning.\n"); else if ($hours < 17) printf("its the afternoon.\n"); else if ($hours < 20) printf("its the evening.\n"); else printf("its nighttime.\n"); break; case 1: printf("i think its around %s.\n", $this->word[($hours + rand(0,3) + 10) % 12]); printf("(but actually i just made that up)\n"); break; case 2: printf("i've got no clue what the time is, go get a watch.\n"); break; case 3: printf("the time is an abstract concept which attempts to give names to different periods of the day or night.\n"); break; case 4: printf("go away, i'm depressed.\n"); break; } exit(0); } echo $this->preface[array_rand($this->preface)]; if ($mins == 0) printf("dead on %s", $this->getword($hours)); else if ($mins <= 3) printf("%s", $this->getword($hours)); else if ($mins <= 7) printf("a bit after %s", $this->getword($hours)); else if ($mins <= 11) printf("ten past %s", $this->getword($hours)); else if ($mins <= 14) printf("nearly quarter past %s", $this->getword($hours)); else if ($mins <= 16) printf("quarter past %s", $this->getword($hours)); else if ($mins <= 19) printf("around twenty past %s", $this->getword($hours)); else if ($mins <= 23) printf("just after twenty past %s", $this->getword($hours)); else if ($mins <= 29) printf("half past %s-ish", $this->getword($hours)); else if ($mins <= 34) printf("half past %s", $this->getword($hours)); else if ($mins <= 36) printf("twenty five to %s", $this->getword($this->nexthour($hours))); else if ($mins <= 39) printf("getting close to twenty to %s", $this->getword($this->nexthour($hours))); else if ($mins <= 41) printf("20 to %s", $this->getword($this->nexthour($hours))); else if ($mins <= 44) printf("almost quarter to %s", $this->getword($this->nexthour($hours))); else if ($mins <= 46) printf("1/4 to %s", $this->getword($this->nexthour($hours))); else if ($mins <= 49) printf("somewhere between %s fourty seven and %s fourty nine", $this->getword($hours), getword($hours)); else if ($mins <= 51) printf("ten to %s", $this->getword($this->nexthour($hours))); else if ($mins <= 54) printf("getting close to 5 minutes to %s", $this->getword($this->nexthour($hours))); else if ($mins <= 56) printf("five to %s", $this->getword($this->nexthour($hours))); else printf("close enough to %s that it doesnt make a difference", $this->getword($this->nexthour($hours))); if (rand(0,1) == 0) { echo $this->vague[array_rand($this->vague)]; } printf(".\n"); } }