home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rxhll.zip / TIMESET.CMD < prev    next >
OS/2 REXX Batch file  |  1993-11-11  |  4KB  |  120 lines

  1. /* REXX */
  2. /* Procedure to call Naval Observatory and set System Time  */
  3. /* Author: Jerry am Ende, Compuserve 73237,131              */
  4. /* Modified: Gary Murphy  01/01/1993                        */
  5. /* Date  : 08/09/92                                         */
  6. /*                                                          */
  7. /* Notes: Change Year to Current Year                       */
  8. /*        Change offset for Daylight Savings Time           */
  9. /*        This version is setup for COM2 change to COM1 if  */
  10. /*          needed                                          */
  11. /*                                                          */
  12.  
  13. parse arg offset PhoneNumber ComPort
  14.  
  15. "CLS"                   /* Clear Screen */
  16.  
  17. if year = "" then do
  18.    say "Usage is: TIMESET <offset> <PhoneNumber> <ComPort>"
  19.    say "          <offset>      = Hours from Greenwich Mean time. Eastern"
  20.    say "                          Standard Time = 5. Default = 6 (CST)"
  21.    say "          <PhoneNumber> = Phone Number of Naval Observatory"
  22.    say "                           1-202-653-0351 is default"
  23.    say "          <ComPort>     = ComPort where modem is connected"
  24.    say "                           COM1 is default"
  25.    return
  26.    end
  27.  
  28. year = left(date('o'),2)            /* Set the year to the last 2 digits */
  29.  
  30. if offset == "" then                /* Set Defaults */
  31.    offset = 6   /* 6 = CST; 5 = CDT */
  32.  
  33. if PhoneNumber == "" then
  34.    PhoneNumber = "1-202-653-0351"
  35.  
  36. if ComPort == "" then
  37.    ComPort = "COM3"
  38.  
  39. modays.1 = 31           /* initialize days in each month */
  40. modays.2 = 28
  41. modays.3 = 31
  42. modays.4 = 30
  43. modays.5 = 31
  44. modays.6 = 30
  45. modays.7 = 31
  46. modays.8 = 31
  47. modays.9 = 30
  48. modays.10 = 31
  49. modays.11 = 30
  50. modays.12 = 31
  51.  
  52. if ((year // 4) == 0) then    /* Check for Leap Year */
  53.    modays.2 = 29
  54.  
  55. CrLf = X2C("0D0A")
  56.  
  57. say "Dialing the Naval Observatory..."
  58.  
  59. State = STREAM(ComPort,"C","OPEN")
  60. "@MODE" ComPort":1200,E,7,1 > NUL"
  61.  
  62. CALL LINEOUT ComPort, "ATX3DT"PhoneNumber||CrLf    /* Dial In */
  63. StartTime = time('E')
  64. ReturnStuff = ""
  65. DO WHILE pos('UTC',ReturnStuff) == 0          /* UTC is end of String */
  66.   ReturnStuff = ReturnStuff||CHARIN(ComPort)
  67.   if (pos('BUSY',ReturnStuff) <> 0) then do   /* Check for Busy */
  68.      CALL LINEOUT ComPort,"ATH"CrLf            /* Hang Up */
  69.      State = STREAM(ComPort,"C","CLOSE")
  70.      Say "Line Busy, Please Try Again..."
  71.      return
  72.      end
  73.   if ((time('E') - StartTime) > 45) then do   /* Check for Timeout */
  74.      CALL LINEOUT ComPort,"ATH"CrLf            /* Hang Up */
  75.      State = STREAM(ComPort,"C","CLOSE")
  76.      Say "Sorry, Timeout..."
  77.      return
  78.      end
  79. END
  80.  
  81. NavalString = Right(ReturnStuff,20)    /* Retrieve the time/date string */
  82.  
  83. CALL LINEOUT ComPort,"ATH"CrLf          /* Hang Up */
  84.  
  85. State = STREAM(ComPort,"C","CLOSE")
  86. parse var NavalString . doy time .
  87.  
  88. /* Convert time to HH:MM:SS */
  89. hour = right(left(time,2) - offset,2,'0')
  90. if (hour < 0) then do
  91.    hour = hour + 24
  92.    doy = doy - 1
  93.    end
  94. minute = right(substr(time,3,2),2,'0')
  95. second = right(substr(time,5,2),2,'0')
  96. TimeString = hour || ':' || minute || ':' || second
  97.  
  98. /* Convert doy to MM-DD-YY format */
  99. month = 0
  100. SumDays = 0
  101. do while (SumDays < doy)
  102.    month = month + 1
  103.    SumDays = SumDays + modays.month
  104. end
  105. SumDays = SumDays - modays.month
  106. Day = doy - Sumdays
  107. DateString = right(Month,2,'0') || '-' || right(Day,2,'0') || '-' || Year
  108.  
  109. OldTime = Time()
  110. OldDate = Date()
  111.  
  112. /* Send Date & Time to OS2 */
  113. "@DATE" DateString
  114. "@TIME" TimeString
  115.  
  116. Say "Date & Time was             " OldDate OLdTime
  117. Say "Date & Time has been Set to:" Date() Time()
  118.  
  119. return
  120.