home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / timeset.zip / TIMESET.CMD next >
OS/2 REXX Batch file  |  1994-07-02  |  5KB  |  166 lines

  1. /* REXX */
  2. /* Procedure to call Naval Observatory and set System Time  */
  3. /* Author: Jerry am Ende, Compuserve 73237,131              */
  4. /* Date  : 08/09/92                                         */
  5. /*                                                          */
  6. /* Notes: Change Year to Current Year                       */
  7. /*        Change offset for Daylight Savings Time           */
  8. /*        This version is setup for COM2 change to COM1 if  */
  9. /*          needed                                          */
  10. /*                                                          */
  11. /* -------------------------------------------------------- */
  12. /*   Update by M.R.Allen 26Sep93  Verison 1.1               */
  13. /*     1) Changed COM read loop to look for two "UTC" then  */
  14. /*        use what is inbetween to set the time.            */
  15. /*     2) Changed Date set routine to only reset the date if*/
  16. /*        the date is different than current system date    */
  17. /*     3) Added defaults section                            */
  18. /*     4) added range check for year,GMT offset, ComPort    */
  19. /*     5) Changed GMT offset to Negative values for time    */
  20. /*        zones West of GMT                                 */
  21. /*     6) Changed Self Doc to call subroutine               */
  22.  
  23. TRACE E
  24.  
  25. parse arg year offset PhoneNumber ComPort
  26.  
  27.  Default_Speed = "2400"
  28.  Default_COM   = "COM1"
  29.  Default_Phone = "1-202-653-0351"
  30.  Default_GMT_Offset = -5
  31.  Default_Connect_Wait = 45
  32.  /* Set default ARGS */
  33. if offset == ""      then  offset = Default_GMT_Offset
  34.  
  35. if PhoneNumber == "" then  PhoneNumber = Default_Phone
  36.  
  37. if ComPort == ""     then  ComPort = Default_COM
  38.  
  39. /* test for ARG within bounries */
  40. if (year = "" | DATATYPE(year) \= "NUM") then do
  41.    CALL Parm_Doc
  42.    say " Year "year" is invalid"
  43.    return
  44.    end
  45. if (DATATYPE(offset) \= "NUM" |  offset < -12 | offset > 12 ) then do
  46.    CALL Parm_Doc
  47.    say " GMT offset "offset" is invalid"
  48.    return
  49.    end
  50. if pos(ComPort,"COM1COM2COM3COM4com1com2com3com4") = 0 then do
  51.    CALL Parm_Doc
  52.    say "COM Port "ComPort" is invalid"
  53.    return
  54.    end
  55.  
  56. modays.1 = 31           /* initialize days in each month */
  57. modays.2 = 28
  58. modays.3 = 31
  59. modays.4 = 30
  60. modays.5 = 31
  61. modays.6 = 30
  62. modays.7 = 31
  63. modays.8 = 31
  64. modays.9 = 30
  65. modays.10 = 31
  66. modays.11 = 30
  67. modays.12 = 31
  68.  
  69. if ((year // 4) == 0) then    /* Check for Leap Year */
  70.    modays.2 = 29
  71.  
  72. CrLf = X2C("0D0A")
  73.  
  74. State = STREAM(ComPort,"C","OPEN")
  75. "@MODE" ComPort":"Default_Speed",E,7,1 > NUL"
  76.  
  77. CALL LINEOUT ComPort, "ATX3DT"PhoneNumber||CrLf    /* Dial In */
  78. StartTime = time('E')
  79. TRACE E
  80. ReturnStuff = " "
  81. UTCcount = 0
  82. pos_start = 1
  83. DO WHILE (UTCcount < 2)
  84.   ReturnStuff = ReturnStuff||CHARIN(ComPort)
  85.   if (pos('BUSY',ReturnStuff) <> 0) then do    /* Check for Busy */
  86.      CALL LINEOUT ComPort,"ATH"CrLf            /* Hang Up */
  87.      State = STREAM(ComPort,"C","CLOSE")
  88.      Say "Line Busy, Please Try Again..."
  89.      return
  90.      end
  91.    /* say "ReturnStuff="ReturnStuff   */
  92.  
  93.   if (pos('UTC',ReturnStuff,pos_start) \= 0) then do
  94.     UTCcount = UTCcount + 1
  95.     pos_start = pos('UTC',ReturnStuff,pos_start) + 1
  96.     end
  97.  
  98.    /* Check for timeout */
  99.    if ((time('E') - StartTime) > Default_Connect_Wait) then do
  100.      CALL LINEOUT ComPort,"ATH"CrLf            /* Hang Up */
  101.      State = STREAM(ComPort,"C","CLOSE")
  102.      Say "Sorry, Timeout..."
  103.      return
  104.      end
  105. END
  106. TRACE E
  107. NavalString = Right(ReturnStuff,20)    /* Retrieve the time/date string */
  108. CALL LINEOUT ComPort,"ATH"CrLf         /* Hang Up */
  109.  
  110. State = STREAM(ComPort,"C","CLOSE")
  111. parse var NavalString . doy time .
  112.  
  113. /* Say "NavalString="NavalString  " doy="doy " time="time */
  114. /* Say "ReturnStuff="ReturnStuff */
  115.  
  116. OldTime = Time()
  117. OldDate = Date()
  118.  
  119. /* Convert time to HH:MM:SS */
  120. hour = right(left(time,2) + offset,2,'0')
  121. if (hour < 0) then do
  122.    hour = hour + 24
  123.    doy = doy - 1
  124.    end
  125. minute = right(substr(time,3,2),2,'0')
  126. second = right(substr(time,5,2),2,'0')
  127. TimeString = hour || ':' || minute || ':' || second
  128. "@TIME" TimeString
  129.  
  130. if date('D') \= doy then do
  131.    /* Convert doy to MM-DD-YY format */
  132.    month = 0
  133.    SumDays = 0
  134.    do while (SumDays < doy)
  135.        month = month + 1
  136.        SumDays = SumDays + modays.month
  137.      end
  138.    SumDays = SumDays - modays.month
  139.    Day = doy - Sumdays
  140.    DateString = right(Month,2,'0') || '-' || right(Day,2,'0') || '-' || Year
  141.    "@DATE" DateString
  142.  end
  143.  
  144. /* Say Date & Time  */
  145.  
  146. Say "Date & Time was             " OldDate OLdTime
  147. Say "Date & Time has been Set to:" Date() Time()
  148.  
  149. return
  150.  
  151. Parm_Doc:
  152.    "CLS"                   /* Clear Screen */
  153.    say " "
  154.    say " Usage is:"
  155.    say "     TIMESET <year> <GMT_offset> <Phone_Number> <ComPort_Number> ";
  156.    say "          <year>            = 2 digit year (e.g. 1992 = 92)";
  157.    say "                              Nodefault, Must be coded";
  158.    say "          <GMT_offset>      = Hours from Greenwich Mean time.";
  159.    say "                                Central Daylight Time = -5";
  160.    say "                                "Default_GMT_Offset" is default";
  161.    say "          <Phone_Number>    = Phone Number of Naval Observatory";
  162.    say "                                "Default_Phone" is default";
  163.    say "          <ComPort_Number>  = ComPort where modem is connected";
  164.    say "                                 "Default_COM" is default";
  165.    return
  166.