home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / pibterm / pibt41s3.arc / PIBTIMER.MOD < prev    next >
Text File  |  1988-01-03  |  12KB  |  255 lines

  1. (*--------------------------------------------------------------------------*)
  2. (*                TimeOfDay  --- Get time of day                            *)
  3. (*--------------------------------------------------------------------------*)
  4.  
  5. FUNCTION TimeOfDay : LONGINT;
  6.  
  7. (*--------------------------------------------------------------------------*)
  8. (*                                                                          *)
  9. (*     Function:  TimeOfDay                                                 *)
  10. (*                                                                          *)
  11. (*     Purpose:   Gets time of day from internal clock                      *)
  12. (*                                                                          *)
  13. (*     Calling sequence:                                                    *)
  14. (*                                                                          *)
  15. (*        Tod := TimeOfDay : LONGINT;                                       *)
  16. (*                                                                          *)
  17. (*           Tod --- Long integer number which is timer value expressed in  *)
  18. (*                   seconds as:                                            *)
  19. (*                   ( 3600 x hour + 60 x minutes + seconds )               *)
  20. (*                                                                          *)
  21. (*     Calls:  GetTime                                                      *)
  22. (*                                                                          *)
  23. (*--------------------------------------------------------------------------*)
  24.  
  25. VAR
  26.    Hours   : WORD;
  27.    Minutes : WORD;
  28.    Seconds : WORD;
  29.    SecHun  : WORD;
  30.  
  31.    TimeVal : LONGINT;
  32.  
  33. BEGIN (* TimeOfDay *)
  34.  
  35.    GetTime( Hours, Minutes, Seconds, SecHun );
  36.  
  37.    TimeVal    := Hours;
  38.    TimeOfDay  := TimeVal * 3600 + Minutes * 60 + Seconds;
  39.  
  40. END   (* TimeOfDay *);
  41.  
  42. (*--------------------------------------------------------------------------*)
  43. (*        TimeDiff  --- Get difference in time between two timer values     *)
  44. (*--------------------------------------------------------------------------*)
  45.  
  46. FUNCTION TimeDiff( Timer1, Timer2: LONGINT ) : LONGINT;
  47.  
  48. (*--------------------------------------------------------------------------*)
  49. (*                                                                          *)
  50. (*     Function:  TimeDiff                                                  *)
  51. (*                                                                          *)
  52. (*     Purpose:   Get difference in time between two timer values in        *)
  53. (*                seconds.                                                  *)
  54. (*                                                                          *)
  55. (*     Calling sequence:                                                    *)
  56. (*                                                                          *)
  57. (*        TDiff := TimeDiff( Timer1, Timer2: LONGINT ) : LONGINT;           *)
  58. (*                                                                          *)
  59. (*           Timer1  --- first timer value (earlier)                        *)
  60. (*           Timer2  --- second timer value (later)                         *)
  61. (*                                                                          *)
  62. (*           TDiff   --- difference between timer values                    *)
  63. (*                                                                          *)
  64. (*     Calls:  None                                                         *)
  65. (*                                                                          *)
  66. (*     Remarks:                                                             *)
  67. (*                                                                          *)
  68. (*        This routine will handle time wrap around midnight.  However, it  *)
  69. (*        only handles timer values <= 24 hours in duration.                *)
  70. (*                                                                          *)
  71. (*--------------------------------------------------------------------------*)
  72.  
  73. CONST
  74.    Secs_Per_Day = 86400    (* Seconds in one day *);
  75.  
  76. VAR
  77.    TDiff : LONGINT;
  78.  
  79. BEGIN (* TimeDiff *)
  80.  
  81.    TDiff := Timer2 - Timer1;
  82.  
  83.    IF ( TDiff < 0 ) THEN 
  84.       TDiff := TDiff + Secs_Per_Day;
  85.  
  86.    TimeDiff := TDiff;
  87.  
  88. END   (* TimeDiff *);
  89.  
  90. (*--------------------------------------------------------------------------*)
  91. (*          TimeString  --- convert timer value to string                   *)
  92. (*--------------------------------------------------------------------------*)
  93.  
  94. FUNCTION TimeString( Timer_Value  : LONGINT;
  95.                      Timer_Format : Time_Format_Type ) : ShortStr;
  96.  
  97. (*--------------------------------------------------------------------------*)
  98. (*                                                                          *)
  99. (*     Function:  TimeString                                                *)
  100. (*                                                                          *)
  101. (*     Purpose:   Convert elapsed timer value to HH:MM:SS string            *)
  102. (*                                                                          *)
  103. (*     Calling sequence:                                                    *)
  104. (*                                                                          *)
  105. (*        Tstring := TimeString( Timer_Value  : LONGINT;                    *)
  106. (*                               Timer_Format : Time_Format_Type ) :        *)
  107. (*                               AnyStr;                                    *)
  108. (*                                                                          *)
  109. (*           Timer_Value ---  Number which is timer value expressed as      *)
  110. (*                            seconds from 12 am.                           *)
  111. (*           Timer_Format --- Format type for time                          *)
  112. (*           Tstring      --- Resultant 'HH:MM:SS' form of time             *)
  113. (*                                                                          *)
  114. (*     Calls:  None                                                         *)
  115. (*                                                                          *)
  116. (*--------------------------------------------------------------------------*)
  117.  
  118. VAR
  119.    Hours   : INTEGER;
  120.    SaveHrs : LONGINT;
  121.    Minutes : INTEGER;
  122.    Seconds : INTEGER;
  123.    Save_H  : LONGINT;
  124.    SH      : STRING[2];
  125.    SM      : STRING[2];
  126.    SS      : STRING[2];
  127.    AmPm    : STRING[3];
  128.  
  129. BEGIN (* TimeString *)
  130.  
  131.    Hours   := Timer_Value DIV 3600;
  132.    SaveHrs := Hours;
  133.    AmPm    := '';
  134.  
  135.    IF ( Timer_Format = AMPM_Time ) THEN
  136.       BEGIN
  137.          Adjust_Hour( Hours , AmPm );
  138.          AmPm := ' ' + AmPm;
  139.       END;
  140.  
  141.    Save_H  := Timer_Value - SaveHrs * 3600;
  142.    Minutes := Save_H DIV 60;
  143.    Seconds := Save_H - Minutes * 60;
  144.  
  145.    STR( Hours:2,   SH );
  146.    STR( Minutes:2, SM );
  147.    STR( Seconds:2, SS );
  148.  
  149.    IF ( Timer_Format <> AMPM_Time ) THEN
  150.       IF SH[1] = ' ' THEN SH[1] := '0';
  151.    IF SM[1] = ' ' THEN SM[1] := '0';
  152.    IF SS[1] = ' ' THEN SS[1] := '0';
  153.  
  154.    TimeString := SH + ':' + SM + ':' + SS + AmPm;
  155.  
  156. END   (* TimeString *);
  157.  
  158. (*--------------------------------------------------------------------------*)
  159. (*             DateString  --- Return current date in string form           *)
  160. (*--------------------------------------------------------------------------*)
  161.  
  162. FUNCTION DateString : ShortStr;
  163.  
  164. (*--------------------------------------------------------------------------*)
  165. (*                                                                          *)
  166. (*     Function:  DateString                                                *)
  167. (*                                                                          *)
  168. (*     Purpose:   Returns current date in string form                       *)
  169. (*                                                                          *)
  170. (*     Calling sequence:                                                    *)
  171. (*                                                                          *)
  172. (*        Dstring := DateString: AnyStr;                                    *)
  173. (*                                                                          *)
  174. (*           Dstring     --- Resultant string form of date                  *)
  175. (*                                                                          *)
  176. (*     Calls:  GetDate                                                      *)
  177. (*                                                                          *)
  178. (*--------------------------------------------------------------------------*)
  179.  
  180. VAR
  181.    SMonth:         STRING[2];
  182.    SDay:           STRING[2];
  183.    SYear:          STRING[4];
  184.    Month:          WORD;
  185.    Day:            WORD;
  186.    Year:           WORD;
  187.    DayOfWeek:      WORD;
  188.  
  189. BEGIN (* DateString *)
  190.                                    (* Date function *)
  191.  
  192.    GetDate( Year, Month, Day, DayOfWeek );
  193.  
  194.                                    (* Convert date to string *)
  195.    STR( Year  , SYear  );
  196.    STR( Day   , SDay   );
  197.    STR( Month , SMonth );
  198.  
  199.    CASE Date_Format OF
  200.       YMD_Style: DateString := SYear  + '/' + SMonth + '/' + SDay;
  201.       DMY_Style: DateString := SDay   + '/' + SMonth + '/' + SYear;
  202.       ELSE
  203.          DateString := SMonth + '/' + SDay + '/' + SYear;
  204.    END (* CASE *);
  205.  
  206. END   (* DateString *);
  207.  
  208. (*--------------------------------------------------------------------------*)
  209. (*              DialDateString  --- Return current date                     *)
  210. (*--------------------------------------------------------------------------*)
  211.  
  212. FUNCTION DialDateString : ShortStr;
  213.  
  214. (*--------------------------------------------------------------------------*)
  215. (*                                                                          *)
  216. (*     Function:  DialDateString                                            *)
  217. (*                                                                          *)
  218. (*     Purpose:   Returns current date in string form                       *)
  219. (*                                                                          *)
  220. (*     Calling sequence:                                                    *)
  221. (*                                                                          *)
  222. (*        Dstring := DialDateString: AnyStr;                                *)
  223. (*                                                                          *)
  224. (*           Dstring     --- Resultant string form of date                  *)
  225. (*                                                                          *)
  226. (*     Calls:  GetDate                                                      *)
  227. (*                                                                          *)
  228. (*--------------------------------------------------------------------------*)
  229.  
  230. VAR
  231.    SMonth:         STRING[2];
  232.    SDay:           STRING[2];
  233.    SYear:          STRING[4];
  234.    Month:          WORD;
  235.    Day:            WORD;
  236.    Year:           WORD;
  237.    DayOfWeek:      WORD;
  238.  
  239. BEGIN (* DialDateString *)
  240.                                    (* Date function *)
  241.  
  242.    GetDate( Year, Month, Day, DayOfWeek );
  243.  
  244.                                    (* Convert date to string *)
  245.    STR( Year  : 4  , SYear  );
  246.    STR( Day   : 2  , SDay   );
  247.    STR( Month : 2  , SMonth );
  248.  
  249.    IF ( SDay[1]   = ' ' ) THEN SDay[1]   := '0';
  250.    IF ( SMonth[1] = ' ' ) THEN SMonth[1] := '0';
  251.  
  252.    DialDateString := SYear[3] + SYear[4] + '/' + SMonth + '/' + SDay;
  253.  
  254. END   (* DialDateString *);
  255.