!! * Copyright Notice
!!  printtime.h 981031
!!  Copyright 1998 Erik Hetzner
!!  This library may be freely distributed, modified, and used. A
!! z-code binary that uses it may be distributed in any manner,
!! provided that credit is given. Any modifications of the library
!! itself for distribution must have this same license and give credit
!! to all authors.
!! * Usage
!!  This library provides three functions: `AnalogTime',
!! `Digital12colonTime', and `Digital24noTime', which can be called in
!! print statements like:
!!
!!  print "The time is: " (Digital12colonTime) the_time ".^";
!!
!!  This will print the time stored in the variable the_time.  This
!! number can be the game time, which is stored in the variable
!! the_time, or any other number or variable. For it to make sense,
!! though, the number must be in the form: (Hours * 60 + Minutes).
!! Enjoy! Send any comments, suggestions, etc. to:
!! Erik Hetzner <[email protected]> 31 October 1998

Constant midnight 00;
Constant noon 12;

[ Hour hr;
   if (hr == midnight)
       print (number) 12;
   else if (hr == noon)
       print (number) 12;
   else
       print (number) hr%12;
];

[ SupHour hr;
   if (hr == midnight)
       print "midnight";
   else if (hr == noon)
       print "noon";
   else
       print (number) hr%12;
];

[ AnalogTime time hr mn past til;
   hr = (time/60); ! set the hour
   mn = (time%60); ! set the minute
   if ((mn == 15) || (mn == 30)) ! Will the time be
       past = true;              ! displayed using `past'?
   if ((mn == 45) || (mn == 50)) ! Will it use
       til = true;               ! `'til'?
   if (til) ! if the time is 'til something, what is is til
       hr = (hr+1)%24;  ! 'til is one hour ahead--compensate for going
   ! past midnight by remaindering by 24.
   switch (mn) {
    0: print (SupHour) hr;
       if (hr ~= midnight && hr ~= noon)
           print " o'clock";
    15: print "quarter past ", (SupHour) hr;
    30: print "half past ", (SupHour) hr;
    45: print "quarter 'til ", (SupHour) hr;
    50: print "ten 'til ", (SupHour) hr;
    1 to 9:
       print (Hour) hr, " oh ", (number) mn;
    10 to 14, 16 to 29, 31 to 44, 46 to 49, 51 to 59:
       print (Hour) hr, " ", (number) mn;
   }
   if ((hr == noon or midnight) && (mn == 0 or 15 or 30
                                            or 45 or 50))
       rtrue; !using noon or midnight; don't need to specify morning/night
   if (hr > midnight && hr < noon )                   ! Is it morning?
       print " in the morning";          ! then make it the suffix.
   else if (hr >= noon && hr <= 18)       ! Perhaps the afternoon?
       print " in the afternoon";
   else
       print " at night";
];

[ Digital24noTime time;
   if (time/60 < 10)   ! Do we need a hr preceeding `0'?
       print "0", time/60; ! then print one
   else
       print time/60;  ! or don't
   if (time%60 < 10)   !do we need a mn preceeding `0'?
       print "0", time%60; ! then print one
   else
       print time%60;  ! or don't
];

[ Digital12colonTime time sep hr mn;
   if (time/60 == midnight || time/60 == noon) ! is it 12?
       hr = 12;  ! then let it be
   else
       hr = (time/60%12); ! or just set the hour...
   mn = (time%60);        ! and set the minute
   if (mn < 10)           ! do we need a mn preceeding `0'?
       sep = ":0";        ! then add one
   else
       sep = ":";         ! or don't
   if ((the_time/60)/12 == 0) ! is it AM?
       print hr, (string) sep, mn, " AM";
   else ! or pm?
       print hr, (string) sep, mn, " PM";
];