home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / RADOOR30.ZIP / TIMER.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-04-10  |  5.6 KB  |  215 lines

  1. {╔═════════════════════════════════════════════════════════════════════════╗
  2.  ║                                                                         ║
  3.  ║                   (c) CopyRight LiveSystems 1990, 1994                  ║
  4.  ║                                                                         ║
  5.  ║ Author    : Gerhard Hoogterp                                            ║
  6.  ║ FidoNet   : 2:282/100.5   2:283/7.33                                    ║
  7.  ║ BitNet    : GERHARD@LOIPON.WLINK.NL                                     ║
  8.  ║                                                                         ║
  9.  ║ SnailMail : Kremersmaten 108                                            ║
  10.  ║             7511 LC Enschede                                            ║
  11.  ║             The Netherlands                                             ║
  12.  ║                                                                         ║
  13.  ║        This module is part of the RADoor BBS doorwriters toolbox.       ║
  14.  ║                                                                         ║
  15.  ╚═════════════════════════════════════════════════════════════════════════╝}
  16.  
  17. Unit Timer;
  18. Interface
  19. Uses Dos;
  20.  
  21.  
  22. Type TimeString  = String[8];
  23.      TimerObject = Object
  24.                      TimeOut   : LongInt;
  25.                      StartTime : LongInt;
  26.                      _24Hour   : Boolean;
  27.  
  28.                      Procedure SetEvent(TimeStr : TimeString);
  29.                      Function EventTime(TimeStr : TimeString):LongInt;
  30.                      Function TestTime(TimeStr : TimeString):Boolean;
  31.                      Function TimeNow:LongInt;
  32.  
  33.                      Procedure SetTimer(TenthsOfSec : LongInt);
  34.                      Function TimeUp:Boolean;
  35.                      Function SecToGo:LongInt;
  36.                      Function TimeToGo:TimeString;
  37.                     End;
  38.  
  39.      ClockObject = Object
  40.                     StartTime  : LongInt;
  41.  
  42.                     Procedure StartTimer;
  43.                     Function GiveTime:TimeString;
  44.                    End;
  45.  
  46. Implementation
  47.  
  48. Const DayTime : LongInt = 864000;
  49.  
  50. Function S(Number : LongInt;Size:Byte):String;
  51. Var HStr : String[20];
  52. Begin
  53. Str(Number:Size,HStr);
  54. S:=HStr;
  55. End;
  56.  
  57. Function Str2Nr(S : String):Word;
  58. Var Temp : Word;
  59.     Err  : Integer;
  60. Begin
  61. Val(S,Temp,Err);
  62. IF Err>0
  63.    Then Str2Nr:=0
  64.    Else Str2Nr:=Temp;
  65. End;
  66.  
  67. Function TimerObject.TestTime(TimeStr : TimeString):Boolean;
  68. Var S2 : String[2];
  69. Begin
  70. TestTime:=False;
  71. S2:=Copy(TimeStr,1,2);
  72. If Not (
  73.    (Str2Nr(S2) in [0..23]) And
  74.    (S2[1] in ['0'..'9']) And
  75.    (S2[2] in ['0'..'9'])
  76.    )
  77.    Then Exit;
  78. S2:=Copy(TimeStr,4,2);
  79. If Not (
  80.    (Str2Nr(S2) in [0..59]) And
  81.    (S2[1] in ['0'..'9']) And
  82.    (S2[2] in ['0'..'9'])
  83.    )
  84.    Then Exit;
  85. TestTime:=True;
  86. End;
  87.  
  88.  
  89.  
  90. Function TimerObject.EventTime(TimeStr : TimeString):LongInt;
  91. Var H,M,S : Word;
  92. Begin
  93. H:=Str2Nr(Copy(TimeStr,1,2));  Delete(TimeStr,1,3);
  94. M:=Str2Nr(Copy(TimeStr,1,2));  Delete(TimeStr,1,3);
  95. S:=Str2Nr(Copy(TimeStr,1,2));
  96. EventTime:=(LongInt(H)*36000)+(LongInt(M)*600)+(LongInt(S)*10);
  97. End;
  98.  
  99. Function TimerObject.TimeNow:LongInt;
  100. Var H,M,S,D : Word;
  101. Begin
  102. GetTime(H,M,S,D);
  103. TimeNow:=(LongInt(H)*36000)+(LongInt(M)*600)+(LongInt(S)*10);
  104. End;
  105.  
  106. Procedure TimerObject.SetEvent(TimeStr : TimeString);
  107. Begin
  108. TimeOut:=EventTime(TimeStr);
  109. If TimeOut=0
  110.    Then TimeOut:=DayTime;
  111. _24Hour:=(TimeOut>=DayTime);
  112. If _24Hour
  113.    Then TimeOut:=TimeOut-DayTime;
  114. End;
  115.  
  116. Procedure TimerObject.SetTimer(TenthsOfSec : LongInt);
  117. Var H,M,S,D : Word;
  118. Begin
  119. GetTime(H,M,S,D);
  120. TimeOut:=(LongInt(H)*36000)+(LongInt(M)*600)+(LongInt(S)*10)+(LongInt(D) Div 10);
  121. TimeOut:=TimeOut+TenthsOfSec;
  122. _24Hour:=(TimeOut>=DayTime);
  123. If _24Hour
  124.    Then TimeOut:=TimeOut-DayTime;
  125. End;
  126.  
  127.  
  128. Function TimerObject.TimeUp:Boolean;
  129. Var Test : LongInt;
  130.     H,M,S,D : Word;
  131. Begin
  132. GetTime(H,M,S,D);
  133. Test:=(LongInt(H)*36000)+(LongInt(M)*600)+(LongInt(S)*10)+(LongInt(D) Div 10);
  134. If _24Hour and (H>0)
  135.    Then Test:=Test-DayTime;
  136. TimeUp:=Test>TimeOut;
  137. End;
  138.  
  139. Function TimerObject.SecToGo:LongInt;
  140. Var Test : LongInt;
  141.     H,M,S,D : Word;
  142. Begin
  143. GetTime(H,M,S,D);
  144. Test:=(LongInt(H)*36000)+(LongInt(M)*600)+(LongInt(S)*10)+(LongInt(D) Div 10);
  145. If _24Hour And (H>0)
  146.    Then Test:=Test-DayTime;
  147. SecToGo:=(TimeOut-Test) Div 10;
  148. End;
  149.  
  150. Function TimerObject.TimeToGo:TimeString;
  151. Var Test      : LongInt;
  152.     HStr      : TimeString;
  153.     H,M,Sec,D : Word;
  154.     Step      : Byte;
  155. Begin
  156. GetTime(H,M,Sec,D);
  157. Test:=(LongInt(H)*36000)+(LongInt(M)*600)+(LongInt(Sec)*10)+(LongInt(D) Div 10);
  158. If _24Hour And (H>0)
  159.    Then Test:=Test-DayTime;
  160. Test:=(TimeOut-Test) Div 10;
  161.  
  162. H:=Test Div 3600;
  163. Test:=Test mod 3600;
  164. M:=Test Div 60;
  165. Test :=Test Mod 60;
  166. Sec:=Test;
  167.  
  168. HStr:=S(H,2)+':'+S(M,2)+':'+S(Sec,2);
  169. For Step:=1 To Length(HStr) Do
  170. If HStr[Step]=' '
  171.    Then HStr[Step]:='0';
  172.  
  173. TimeToGo:=HStr;
  174. End;
  175.  
  176.  
  177.  
  178.  
  179. Procedure ClockObject.StartTimer;
  180. Var H,M,S,D : Word;
  181. Begin
  182. GetTime(H,M,S,D);
  183. StartTime:=(LongInt(H)*3600)+(LongInt(M)*60)+(LongInt(S));
  184. End;
  185.  
  186. Function ClockObject.GiveTime:TimeString;
  187. Var  CurrTime  : Longint;
  188.      HStr      : TimeString;
  189.      Step      : Byte;
  190.      H,M,Sec,D : Word;
  191. Begin
  192. GetTime(H,M,Sec,D);
  193. CurrTime:=(LongInt(H)*3600)+(LongInt(M)*60)+(LongInt(Sec));
  194. CurrTime:=CurrTime-StartTime;
  195. If CurrTime<0
  196.    Then Inc(CurrTime,(DayTime div 10));
  197.  
  198. H:=CurrTime Div 3600;
  199. CurrTime:=CurrTime mod 3600;
  200. M:=CurrTime Div 60;
  201. CurrTime:=CurrTime Mod 60;
  202. Sec:=CurrTime;
  203.  
  204. HStr:=S(H,2)+':'+S(M,2)+':'+S(Sec,2);
  205. For Step:=1 To Length(HStr) Do
  206. If HStr[Step]=' '
  207.    Then HStr[Step]:='0';
  208.  
  209. GiveTime:=HStr;
  210. End;
  211.  
  212. End.
  213.  
  214.  
  215.