home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / proglc / timeutil.lzh / TIMEUTIL.DOC < prev    next >
Encoding:
Text File  |  1988-04-10  |  3.8 KB  |  94 lines

  1.  
  2.  
  3.                              Time Utilities
  4.                              by Jim Colligan
  5.  
  6.  
  7.         These programs are utilities designed to be executed in .BATch
  8.         files.  The need for them came through running a bulletin board
  9.         system, but could be used for other purposes.  They were compiled
  10.         with Borland's Turbo C compiler version 1.5 and full source code
  11.         is included.  The programs include:
  12.  
  13.         WAIT.EXE - This program merely goes and gets the DOS time and does
  14.                 nothing until the next whole minute rolls around.  While
  15.                 this may seem like a quite trivial program, I did have a
  16.                 need for it in a .BAT file.  I had a particular event set
  17.                 to execute at a set time.  But for shorter events, it would
  18.                 take far less than a minute and the entire sequence would
  19.                 be repeated over and over and over until the clock finally
  20.                 ticked over to the next minute.  This program can be aborted
  21.                 by pressing ^C.
  22.  
  23.         WAITUNTL.EXE - Similar to the above, but this one waits until a
  24.                 set hour and minute before exiting.  The usage is merely:
  25.  
  26.                     WAITUNTL xx:yy
  27.  
  28.                 where xx is the hour (24 hour clock) and yy is the minute
  29.                 you want to "pause" until.  It will work over midnight so
  30.                 a program can be set in a .BATch file and executed at any
  31.                 time and it will properly wait until the appointed hour
  32.                 before relinguishing control back to the .BATch file.  
  33.                 Handy as an "alarm clock" for the system when you want a
  34.                 BAT file or other program to kick off at a certain time.  
  35.                 This program can also be aborted by pressing ^C.
  36.  
  37.         TIMECHK.EXE - This program reads the DOS clock and merely sets an
  38.                 errorlevel for DOS accordingly.  I use this on my bulletin
  39.                 board so no matter what time of the day my RUNBBS.BAT file
  40.                 is started, it'll start executing at the right place
  41.                 (different tasks/places for different times of the day).
  42.  
  43.                 Unfortunately, there's only 256 available errorlevel codes
  44.                 available, so you can't cut up the day down to the exact
  45.                 minute.  But, I have coded it so you can come down to the
  46.                 nearest 10 minutes.  Not perfect, but workable.
  47.  
  48.                 The errorlevels kicked out are determined by the formula
  49.                 (hours * 10) + (minutes / 10).  Reasonably simple.  What
  50.                 this means in english is that 11:17 will produce an error-
  51.                 level of 111.  Here's some additional examples:
  52.  
  53.                     Time    Errorlevel
  54.                     ----    ----------
  55.                     01:23      012
  56.                     10:20      102
  57.                     15:01      150
  58.                     21:29       212
  59.                     23:59      235
  60.  
  61.                 I think you get the idea.  The individual minutes are
  62.                 dropped (integer arithmetic) and the error code can be
  63.                 looked at as (HHM) where HH is the hour of the day and the
  64.                 M is the # of tens of minutes.
  65.  
  66.                 A .BATch file that would use TIMECHK would look something
  67.                 like (or a portion of the .BAT file):
  68.  
  69.                 timechk
  70.                     if errorlevel 210 goto NITETIME
  71.                     if errorlevel 170 goto EVENING
  72.                     if errorlevel 120 goto NOON
  73.                     if errorlevel 080 goto MORNING
  74.                     if errorlevel 000 goto NITETIME
  75.  
  76.                 Where NITETIME, EVENING, NOON, and MORNING were different
  77.                 labels in a .BATch file and did different things according
  78.                 to the time of day.  Note: because of the way .BATch file
  79.                 errorlevels are evaluated, you must use a reverse order
  80.                 (highest first) for proper branching.  Also, if you want
  81.                 an event or condition to "start" prior to midnight and
  82.                 finish after midnight, you must use two entries (the second
  83.                 would "start" just after midnight.
  84.  
  85.             With all of these programs, full source code is distributed
  86.             with them so you can modify to your heart's content.  No
  87.             guarantees of any sort are provided.  I've found them useful
  88.             and use them as distributed on my own computers including my
  89.             bulletin board.  Enjoy!!!
  90.  
  91.                                     Jim Colligan
  92.                                     Fidonet 372/1 or 18/3
  93.  
  94.