channelping exactly twenty past two in the morning

ProseClock an alternative to digital and analog time displays

<?php
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
//                                                                       //
//  ProseClock: an alternative to digital and analog formats             //
//                                                                       //
//  Copyright (c) 2005-Eternity Gerald Gold and channelping. All rights  //
//  reserved. This class is free software; you may redistribute it       //
//  and/or modify it under the same terms as PHP itself.                 //
//                                                                       //
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
class ProseClock
{
  var $time;
  var $min_phrase;
  var $mul_phrase;
  var $hour_phrase;
  var $mul;

  function ProseClock()
  {
      $this->time = getdate();
      $this->_set_minute_maps();
      $this->_set_hour_map();
  }

  function showTime()
  {
      if (strlen($this->mul_phrase))
      {
          $this->min_phrase .= ' ';
      }
      return "$this->min_phrase{$this->mul_phrase} $this->hour_phrase";
  }

  function _set_hour_map()
  {
      $phrase =
          array(
            0 => 'midnight',
            1 => 'one in the morning',
            2 => 'two in the morning',
            3 => 'three in the morning',
            4 => 'four in the morning',
            5 => 'five in the morning',
            6 => 'six in the morning',
            7 => 'seven in the morning',
            8 => 'eight in the morning',
            9 => 'nine in the morning',
            10 => 'ten in the morning',
            11 => 'eleven in the morning',
            12 => 'noon',
            13 => 'one in the afternoon',
            14 => 'two in the afternoon',
            15 => 'three in the afternoon',
            16 => 'four in the afternoon',
            17 => 'five in the evening',
            18 => 'six at night',
            19 => 'seven at night',
            20 => 'eight at night',
            21 => 'nine at night',
            22 => 'ten at night',
            23 => 'eleven at night',
            );

    $hours = $this->time['hours'];

    if ($this->mul >= 35)
    {
      ($hours == 23) ? $hours = 0 : $hours++;
    }

    $this->hour_phrase = $phrase[$hours];

    if ($phrase[$hours] == 0 &&
        $this->time['minutes'] < 3)
    {
      $this->mul_phrase = '';
    }
  }

  function _set_minute_maps()
  {
    $minutes = $this->time['minutes'];
    $multiple =
      array(
            0 => "o'clock",
            5 => 'five past',
            10 => 'ten past',
            15 => 'quarter past',
            20 => 'twenty past',
            25 => 'twenty-five past',
            30 => 'half past',
            35 => 'twenty-five to',
            40 => 'twenty to',
            45 => 'quarter to',
            50 => 'ten to',
            55 => 'five to',            
            60 => '',
            );

    $phrase =
      array(
            0 => 'exactly',
            1 => 'just after',
            2 => 'a little after',
            3 => 'coming up to',
            4 => 'almost'
            );

    $remainder = $minutes % 5;

    $this->mul = $minutes - $remainder;

    // switch frame of reference
    if ($remainder >=3)
    {
      $this->mul += 5;
    }

    $this->min_phrase = $phrase[$remainder];
    $this->mul_phrase = $multiple[$this->mul];
  }
}
?>

^