{***********************************************************************}
{									}
{ __TimeStr   Return the system time					}
{									}
{ function  __TimeStr(var Hours, Minutes,				}
{			  Seconds, Tics : word) : string;		}
{									}
{	      Hours	The returned hour in the range 0 to 23 .	}
{	      Minutes	The returned minute in the range 0 to 59 .	}
{	      Seconds	The returned second in the range 0 to 59 .	}
{	      Tics	The returned hundredth of second in the range	}
{			0 to 99 .					}
{									}
{ Description __TimeStr returns the system time in the word variables	}
{	      Hours, Minutes, Seconds and Tics.  The time is also	}
{	      returned as the functional value in the form  HH:MM AM or }
{	      PM.  For example, 18:36:55.72 is returned as		}
{									}
{			      6:37 PM					}
{									}
{	      Notice that the minutes are rounded up, and, therefore,	}
{	      possibly the hours as well.  However, if the hour is	}
{	      moved past midnight, the system date is not altered.	}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc. 1987		}
{_______________________________________________________________________}

function  __TimeStr(var Hours, Minutes,
			Seconds, Tics : word) : string;
  const
    COLON   = ':';

  type
    AmPm    = array[0..1] of string[3];

  const
    AmPmStr : AmPm   = (' AM',' PM');

  var
    TmpHours,TmpMins : word;
    HourStr,MinStr   : string[2];
    AmIndex	     : word;
    Regs	     : registers;

  begin {__TimeStr}

    GetTime(Hours,Minutes,Seconds,Tics);
    TmpHours := Hours;		       { Now round the minutes and pos- }
    TmpMins  := Minutes;	       { sibly the hours also.		}
    if (Seconds > 30) then
       begin			       { Round up the minutes.		}
	 TmpMins := Succ(TmpMins) mod 60;
	 if (TmpMins = 0) then	       { Must up the hours.		}
	    TmpHours := Succ(TmpHours) mod 24
       end;

    if (TmpHours < 12) then	       { Now construct the string	}
       begin
	 AmIndex := 0;		       { It is the morning.		}
	 if (TmpHours = 0) then        { It is midnight.		}
	    TmpHours := 12
       end
    else
       begin
	 AmIndex := 1;		       { It is afternoon.		}
	 if (TmpHours > 12) then       { It is past noon.		}
	    TmpHours := TmpHours - 12
       end;

    Str(TmpMins:2,MinStr);	       { Now construct the string...	}
    if (TmpMins < 10) then
       MinStr[1] := '0';
    Str(TmpHours,HourStr);

    __TimeStr := HourStr + COLON + MinStr + AmPmStr[AmIndex]

  end;	{__TimeStr}
