DEFINITION MODULE DateConversions;
(*$ NameChk:=FALSE *)
(*
 * This modules handles times and dates in the range of
 * 00:00:00.000000 1 March 1900 - 23:59:59.999999 of the
 * 28 February 2100
 *)

FROM DosD IMPORT Date;
FROM Timer IMPORT TimeVal;

CONST
 month3="Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec";
 month="January|February|March|April|May|June|July|August|September|October|November|December";

TYPE
 DateInfo=RECORD
  minutes:LONGINT;
  micros:LONGINT;
 END;
(*
 * Containes the minutes and microseconds passed
 * since 00:00 of the 1. March 1900
 *)

PROCEDURE FromDos(d:Date; VAR di:DateInfo);
PROCEDURE FromTimer(t:TimeVal; VAR di:DateInfo);

PROCEDURE ToDos(di:DateInfo; VAR d:Date);
PROCEDURE ToTimer(di:DateInfo; VAR t:TimeVal);

PROCEDURE DecodeDate(minutes:LONGINT;
                     VAR day,month,year:INTEGER);
PROCEDURE EncodeDate(day,month,year:INTEGER;
                     VAR minutes:LONGINT);

PROCEDURE DateToStr(di:DateInfo; formatString,
                    monthText:ARRAY OF CHAR;
                    VAR output:ARRAY OF CHAR);
(*
 * The formatstring specifies which fields of the should
 * appear in the ouput string. The format string can
 * inlude normal text as well as format commands, e.g.
 *
 *   "Date: %d. %t %Y  Time: %H:%M:%S.%3"
 *
 * This format would result in a string like
 *
 *   Date: 25 July 1989  Time: 22:33:21.423
 *
 * The format commands are introduced by a % and are:
 *
 *  %E   Escape
 *  %N   Newline
 *  %T   Tab
 *  %%   %
 *  %d   day as 2 digit number
 *  %m   month as 2 digit number
 *  %t   month as text
 *  %y   year as 2 digit number
 *  %Y   year as 4 digit number
 *  %H   hour as 2 digit number
 *  %M   minute as 2 digit number
 *  %S   second as 2 digit number
 *  %1   tenth seconds as 1 digit number
 *  %2   hundreth seconds as 2 digit number
 *  %3   ...
 *  .
 *  %6   microsecond as 6 digit number
 *)

END DateConversions.
