#!/usr/local/bin/php -q
<?php
/** -*- php3 -*- **************************************************************
 * Copyright © 1999 Klaus Alexander Seistrup @ Magnetic Ink, Copenhagen, DK.
 *
 * Author  : Klaus Alexander Seistrup <kseis@magnetic-ink.dk>
 * Created : Saturday, 23rd January 1999
 * @(#) $Id: qtime.php3,v 1.4 1999/01/29 11:51:57 kseis Exp $
 *
 * This is my first attempt of programming in PHP3. :-)
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but with-
 * out any warranty; without even the implied warranty of merchantability or
 * fitness for a particular purpose.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 ******************************************************************************/

function seconds_since_midnight ()
{
  $now = time ();

  $hh = date ("H", $now);
  $mm = date ("i", $now);
  $ss = date ("s", $now);

  return ($hh * 60 + $mm) * 60 + $ss;
}

function qt ()
{
  $Hr[] = "twelve";	/* Is this the easiest way to make arrays? Argh! */
  $Hr[] = "one";
  $Hr[] = "two";
  $Hr[] = "three";
  $Hr[] = "four";
  $Hr[] = "five";
  $Hr[] = "six";
  $Hr[] = "seven";
  $Hr[] = "eight";
  $Hr[] = "nine";
  $Hr[] = "ten";
  $Hr[] = "eleven";

  $Mn[] = "";
  $Mn[] = "five ";
  $Mn[] = "ten ";
  $Mn[] = "a quarter ";
  $Mn[] = "twenty ";
  $Mn[] = "twenty-five ";
  $Mn[] = "half ";

  $Ny[] = "nearly ";
  $Ny[] = "almost ";
  $Ny[] = "";
  $Ny[] = "just after ";
  $Ny[] = "after ";

  $Up[] = "to ";
  $Up[] = "";
  $Up[] = "past ";

  /* It sure looks a lot like C, doesn't it? */
  $adj_mins	= (int) ((seconds_since_midnight () + 30) / 60) + 27;
  $hours	= (int) ($adj_mins / 60) % 12;
  $minutes	= $adj_mins % 60;
  $almost	= $minutes % 5;
  $divisions	= (int) ($minutes / 5) - 5;
  $to_past_idx	= $divisions > 0 ? 1 : 0;

  if ($divisions < 0)
    {
      $divisions = -$divisions;
      $to_past_idx = -1;
    }
  $to_past_idx++;

  echo "It's ", $Ny[$almost], $Mn[$divisions], $Up[$to_past_idx], $Hr[$hours];

  if ($divisions == 0)
    echo " o'clock";

  echo ".\n";
}

qt ();	/* Spill the beans */

/* EOF */
?>
