home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / pibasy.zip / PIBTIMER.PAS < prev    next >
Pascal/Delphi Source File  |  1987-11-11  |  5KB  |  100 lines

  1. UNIT PibTimer;
  2.  
  3. INTERFACE
  4.  
  5. USES   
  6.    Dos, GlobType;
  7.  
  8. FUNCTION TimeOfDay : LONGINT;
  9. FUNCTION TimeDiff( Timer1, Timer2: LONGINT ) : LONGINT;
  10.  
  11. IMPLEMENTATION
  12.  
  13. (*--------------------------------------------------------------------------*)
  14. (*                TimeOfDay  --- Get time of day                            *)
  15. (*--------------------------------------------------------------------------*)
  16.  
  17. FUNCTION TimeOfDay : LONGINT;
  18.  
  19. (*--------------------------------------------------------------------------*)
  20. (*                                                                          *)
  21. (*     Function:  TimeOfDay                                                 *)
  22. (*                                                                          *)
  23. (*     Purpose:   Gets time of day from internal clock                      *)
  24. (*                                                                          *)
  25. (*     Calling sequence:                                                    *)
  26. (*                                                                          *)
  27. (*        Tod := TimeOfDay : LONGINT;                                       *)
  28. (*                                                                          *)
  29. (*           Tod --- Long integer number which is timer value expressed in  *)
  30. (*                   seconds as:                                            *)
  31. (*                   ( 3600 x hour + 60 x minutes + seconds )               *)
  32. (*                                                                          *)
  33. (*     Calls:  GetTime                                                      *)
  34. (*                                                                          *)
  35. (*--------------------------------------------------------------------------*)
  36.  
  37. VAR
  38.    Hours   : WORD;
  39.    Minutes : WORD;
  40.    Seconds : WORD;
  41.    SecHun  : WORD;
  42.     
  43. BEGIN (* TimeOfDay *)
  44.  
  45.    GetTime( Hours, Minutes, Seconds, SecHun );
  46.    
  47.    TimeOfDay  := Hours * 3600 + Minutes * 60 + Seconds;
  48.  
  49. END   (* TimeOfDay *);
  50.  
  51. (*--------------------------------------------------------------------------*)
  52. (*        TimeDiff  --- Get difference in time between two timer values     *)
  53. (*--------------------------------------------------------------------------*)
  54.  
  55. FUNCTION TimeDiff( Timer1, Timer2: LONGINT ) : LONGINT; 
  56.  
  57. (*--------------------------------------------------------------------------*)
  58. (*                                                                          *)
  59. (*     Function:  TimeDiff                                                  *)
  60. (*                                                                          *)
  61. (*     Purpose:   Get difference in time between two timer values in        *)
  62. (*                seconds.                                                  *)
  63. (*                                                                          *)
  64. (*     Calling sequence:                                                    *)
  65. (*                                                                          *)
  66. (*        TDiff := TimeDiff( Timer1, Timer2: LONGINT ) : LONGINT;           *)
  67. (*                                                                          *)
  68. (*           Timer1  --- first timer value (earlier)                        *)
  69. (*           Timer2  --- second timer value (later)                         *)
  70. (*                                                                          *)
  71. (*           TDiff   --- difference between timer values                    *)
  72. (*                                                                          *)
  73. (*     Calls:  None                                                         *)
  74. (*                                                                          *)
  75. (*     Remarks:                                                             *)
  76. (*                                                                          *)
  77. (*        This routine will handle time wrap around midnight.  However, it  *)
  78. (*        only handles timer values <= 24 hours in duration.                *)
  79. (*                                                                          *)
  80. (*--------------------------------------------------------------------------*)
  81.  
  82. CONST
  83.    Secs_Per_Day = 86400    (* Seconds in one day *);
  84.  
  85. VAR
  86.    TDiff : LONGINT;
  87.  
  88. BEGIN (* TimeDiff *)
  89.  
  90.    TDiff := Timer2 - Timer1;
  91.  
  92.    IF ( TDiff < 0 ) THEN 
  93.       TDiff := TDiff + Secs_Per_Day;
  94.  
  95.    TimeDiff := TDiff;
  96.  
  97. END   (* TimeDiff *);
  98.  
  99. END (* PibTimer *).
  100.