PROCEDURE (ram$dist) display_time, dist (
  output, o: file = $output
  status)

" PURPOSE:
"   Converts the current time into word format and displays it to a file.
" DESIGN:
"   The displayed time is accurate to within five minutes.

  VAR
    hour_name: array 1 .. 12 of string
    sector_name: array 1 .. 12 of string
    time: string = $justify($time(ampm), 8, right)
    hour: integer = $integer(time(1, 2))
    minute: integer = $integer(time(4, 2))
    hour_string: (DEFER) string = hour_name(1 + $mod(hour+$integer(32<minute), 12))
    sector_string: (DEFER) string = sector_name(1 + $mod(minute/5+$integer($mod(minute, 5)>2), 12))
    the_time: string
  VAREND

  hour_name(1)='twelve'
  hour_name(2)='one'
  hour_name(3)='two'
  hour_name(4)='three'
  hour_name(5)='four'
  hour_name(6)='five'
  hour_name(7)='six'
  hour_name(8)='seven'
  hour_name(9)='eight'
  hour_name(10)='nine'
  hour_name(11)='ten'
  hour_name(12)='eleven'

  sector_name(1)='o''clock'
  sector_name(2)='five'
  sector_name(3)='ten'
  sector_name(4)='quarter'
  sector_name(5)='twenty'
  sector_name(6)='twenty-five'
  sector_name(7)='half'
  sector_name(8)='twenty-five'
  sector_name(9)='twenty'
  sector_name(10)='quarter'
  sector_name(11)='ten'
  sector_name(12)='five'

  IF sector_string = 'o''clock' THEN
    the_time=$char(bel)// hour_string // ' o''clock, and all''s well'
  ELSEIF minute > 32 THEN
    the_time = sector_string // ' to ' // hour_string
  ELSE
    the_time = sector_string // ' past ' // hour_string
  IFEND

  put_line line=' '//the_time output=output

PROCEND display_time
