home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / easyon1a.zip / EASYTIME.CMD < prev    next >
OS/2 REXX Batch file  |  1993-09-27  |  7KB  |  244 lines

  1. /* EasyTime */
  2. /* Ver 1.0 */
  3. /* Copyright 1993 by Mark Bernard */
  4.  
  5. /*******************/
  6. /** Configuration **/
  7. /*******************/
  8.  
  9. /** Paths and Filenames **/
  10. LogFile = "C:\bink\bink.log"
  11. FlagFile = "C:\maxp\EasyTime.Flg"  /* Flag File */
  12. EasyOnLog = "C:\bink\EasyOn.log"   /* To log time adjustments */
  13.  
  14. /** Options: 1 = yes, 0 = no **/
  15.  
  16. LogTimeChange = 1
  17.  
  18. /** Other **/
  19.  
  20. TimeZone = 0  /* offset from LOCAL time - limit of ± 23 */
  21. DateString = "Date ="
  22. TimeString = "Time ="
  23. ConnectString = "Connect "
  24.  
  25.  
  26. /** End Configuration **/
  27. /***********************/
  28.  
  29. arg p.1 p.2
  30.  
  31. DoFlag = linein(FlagFile,1,1)
  32. DoFlag = strip(DoFlag,'Both')
  33.  
  34. if DoFlag = "Loaded" then
  35.   do
  36.     if RxFuncquery(SysLoadFuncs) > 0 then
  37.       do
  38.         call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  39.         call SysLoadFuncs
  40.       end /* do */
  41.  
  42.    
  43.     call SysFileSearch DateString, LogFile,'hit.',N
  44.  
  45.     do i=1 to hit.0; end /* do */
  46.     i=(i-1)
  47.     LineNum = word(hit.i,1)
  48.     LineNum = strip(LineNum,'B')
  49.       /*line number of last "DateString" hit */
  50.  
  51.     call SysFileSearch ConnectString, Logfile, 'con.',N
  52.  
  53.     do j = 1 to con.0; end /* do */
  54.     j = (j-1)
  55.  
  56.     LineCon = word(con.j,1)
  57.     LineCon = strip(LineCon,'B')
  58.  
  59.       /* Line number of last "Connect" message */
  60.  
  61.     if ((LineCon > LineNum) & ((LineCon-LineNum) < 5)) then /* use */
  62.       do
  63.          TeleDate = hit.i
  64.          DatePos = pos(DateString, hit.i) + length(DateString)
  65.            /* position of the result code in TeleDate */
  66.          
  67.          TeleDate = substr(TeleDate, DatePos)
  68.          TeleDate = strip(TeleDate, 'Both')
  69.            /* remove leading and trailing blanks */
  70.  
  71.          call SysFileSearch TimeString, Logfile, 'hit.',N
  72.  
  73.          do i = 1 to hit.0; end /* do */
  74.          i = (i-1)
  75.  
  76.          TeleTime = hit.i
  77.          TimePos = pos(TimeString, hit.i) + length(TimeString)
  78.            /* position of the result code in TeleDate */
  79.  
  80.          TeleTime = substr(TeleTime, TimePos)
  81.          TeleTime = strip(TeleTime, 'Both')
  82.            /* remove leading and trailing blanks */
  83.          Tyear = substr(date('O'),1, 2)
  84.          Tmonth = substr(Teledate, 1, 2)
  85.          Tmonth = strip(Tmonth, 'Leading', "0")
  86.          Tday = substr(Teledate, 3, 2)
  87.          Tday = strip(Tday, 'Leading', "0")
  88.          Thour = substr(TeleTime, 1, 2)
  89.          Thour = strip(Thour, 'Leading', "0")
  90.          Tmin = substr(TeleTime, 3, 2)
  91.  
  92.          call TZadjust TimeZone
  93.  
  94.          if length(Tyear) < 2 then TYear = insert("0", Tyear)
  95.          if length(Tmonth) < 2 then Tmonth = insert("0", Tmonth)
  96.          if length(Tday) < 2 then Tday = insert("0", Tday)
  97.          if length(Thour) < 2 then Thour = insert("0", Thour)
  98.          if length(TMin) < 2 then Tmin = insert("0", Tmin)
  99.          
  100.          TeleDate = insert(Tday, Tyear,0,3,"-")
  101.          TeleDate = insert(Tmonth, TeleDate,0,3,"-")
  102.          TeleTime = insert(Tmin, "30", 0, 3, ":")
  103.          TeleTime = insert(Thour,TeleTime, 0, 3, ":")
  104.       end /* use */
  105.  
  106.     if LogTimeChange = 1 then do
  107.       LogDate = date('N')
  108.       Entry = TeleTime
  109.       Entry = insert(" / ", Entry)
  110.       Entry = insert(TeleDate, Entry)
  111.       Entry = insert(" EasyTime: Reset to: ", Entry)
  112.       Entry = insert(time('N'), Entry)
  113.  
  114.       dd = word(LogDate, 1)
  115.       if length(dd) = 1 then dd = insert("0", dd)
  116.       mon = word(LogDate, 2)
  117.       yy = word(Logdate, 3)
  118.       yy = substr(yy, 3)
  119.       
  120.       Entry = insert(dd, Entry, 0, 3, " ") /* mon */
  121.       Entry = insert(mon, Entry, 0, 4, " ") /* dd */
  122.       Entry = insert(yy, Entry, 0, 3, " ") /* yy mon dd time*/
  123.       Entry = insert("# ", Entry)
  124.  
  125.      
  126.       call lineout EasyOnLog, Entry  
  127.       end /* do - LogTimeChange */
  128.  
  129.     "DATE" TeleDate   /* set system date and time */
  130.     "TIME" TeleTime 
  131.     call lineout FlagFile, "UnLoaded ",1  /* "UnLoad" EasyTime */
  132.  
  133.  
  134.   end /* do - "Loaded" */
  135.  
  136. exit
  137.  
  138. TZAdjust:
  139.  
  140.  TZ = arg(1)
  141.  Thour = Thour + TZ
  142.  if TZ = 0 then nop
  143.  else if Thour > 23 | Thour < 0 then do    /* other day */
  144.    if Thour > 23 then do       /* next day */
  145.      Thour = Thour - 24
  146.      Tday = Tday + 1
  147.      select
  148.        when Tmonth = 2 & Tday > 28 then do
  149.          if (Tyear/4 - format(Tyear/4,4,0)) = 0 then do
  150.            if Tday > 29 then do
  151.              Tmonth = 3
  152.              Tday = 1
  153.              end /* do */
  154.            end /* do */
  155.            else do         /* not a leap year */
  156.              TMonth = 3
  157.              Tday = 1
  158.              end /* do */
  159.          end /*do */
  160.        when Tmonth = 4 then if Tday > 30 then do
  161.          Tmonth = 5
  162.          Tday = 1
  163.          end /* do */
  164.        when Tmonth = 6 then if Tday > 30 then do
  165.          Tmonth = 7
  166.          Tday = 1
  167.          end /* do */
  168.        when Tmonth = 9 then if Tday > 30 then do
  169.          Tmonth = 10
  170.          Tday = 1
  171.          end /* do */
  172.        when Tmonth = 11 then if Tday > 30 then do
  173.          Tmonth = 12
  174.          Tday = 1
  175.          end /* do */
  176.        when Tmonth = 12 then if Tday > 31 then do
  177.          Tyear = Tyear + 1
  178.          Tmonth = 1
  179.          Tday = 1
  180.          end /* do */
  181.        otherwise do
  182.          if Tday > 31 then do
  183.            Tmonth = Tmonth + 1
  184.            Tday = 1
  185.            end /* do */
  186.          end /* do */
  187.        end /* select */
  188.      end /* do - next day */
  189.  
  190.      else do        /* previous day */
  191.        Thour = 24 + Thour
  192.        Tday = Tday - 1
  193.        if Tday < 1 then
  194.          select
  195.            when Tmonth = 1 then do
  196.              Tyear = Tyear - 1
  197.              Tmonth = 12
  198.              Tday = 31
  199.              end /* do */
  200.            when Tmonth = 3 then do
  201.              if (Tyear/4 - format(Tyear/4,4,0) = 0) then do
  202.                Tmonth = 2
  203.                Tday = 29
  204.                end /* do */
  205.              else do          /* not a leap year */
  206.                TMonth = 2
  207.                Tday = 28
  208.                end /* do */
  209.              end /* do */
  210.            when Tmonth = 5 then do
  211.              Tmonth = 4
  212.              Tday = 30
  213.              end /* do */
  214.            when Tmonth = 7 then do
  215.              Tmonth = 6
  216.              Tday = 30
  217.              end /* do */
  218.            when Tmonth = 10 then do
  219.              Tmonth = 9
  220.              Tday = 30
  221.              end /* do */
  222.            when Tmonth = 12 then do
  223.              Tmonth = 11
  224.              Tday = 30
  225.              end /* do */
  226.            otherwise do
  227.              Tmonth = Tmonth - 1
  228.              Tday = 31
  229.              end /* do */
  230.            end /* select */
  231.        end /* do - previous day */
  232.    end /* do Other day */
  233.  
  234. return
  235.  
  236.  
  237.  
  238.  
  239.  
  240.      
  241.  
  242.  
  243.  
  244.