home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / dyltswch.lzh / DYLTSWCH.TXT < prev    next >
Text File  |  1995-04-06  |  8KB  |  129 lines

  1.                    Switching To/From Daylight Saving Time
  2.  
  3. Legalese
  4. The computer program docuemnted here is the copyrighted property of David William
  5. Noon, published 1995. The program may be distributed freely, provided that the
  6. copies distributed are not altered from the original and that no charge is levied beyond
  7. the price of the medium of distribution. The author does not relinquish the rights of
  8. this intellectual property.
  9.  
  10. Overview
  11. Twice a year, every year, it becomes necessary to change the Time-Of-Day (or TOD)
  12. clock on every computer you own. This is a chore that the computer itself should be
  13. able to handle. Well, now it is able to handle it.
  14.  
  15. The switching to and from Daylight Saving Time can now be automated by means of a
  16. program that remains in the background using no CPU cycles except on those two
  17. occasions each year when the clocks need to be changed. Such a program is included in
  18. the archive with this document.
  19.  
  20. The Program
  21. The program DYLTSWCH.EXE functions under OS/2 like a daemon does under Unix.
  22. It "sleeps" in the background, waking up only at selected times. When it does wake up
  23. it adjusts the machine's TOD clock and then goes back to sleep for another 6 months (or
  24. so).
  25.  
  26. Since I have included the source code in the archive you can see for yourself how this is
  27. achieved. The DELAY statement of PL/I is a thin wrapper over the DosSleep() API call.
  28.                   Switching To/From Daylight Saving Time
  29.  
  30. Defining Your Time Zone to the Operating System
  31. The program uses the TZ environment variable. This variable defines the time zone in
  32. which the computer resides; its value can be set by means of a SET command,
  33. preferably in your CONFIG.SYS file. This variable is one OS/2 has inherited from Unix
  34. and the default settings are for Bell Laboratories in New Jersey, where Unix was first
  35. developed. The following is the definition of the fields within the TZ variable.
  36. ╔═══════════════════════════════════════════════════════════════════════════╗
  37. ║Variable  │ Description                                     │ Default      ║
  38. ║──────────┼─────────────────────────────────────────────────┼──────────────║
  39. ║SSS       │ Standard time zone identifier. This must        │ EST          ║
  40. ║          │ be 3 characters, must begin with letter         │              ║
  41. ║          │ and can contain spaces                          │              ║
  42. ║──────────┼─────────────────────────────────────────────────┼──────────────║
  43. ║n         │ Difference, in hours, between the               │ +5           ║
  44. ║          │ standard time zone and Coordinated              │              ║
  45. ║          │ Universal Time (CUT), formerly know as          │              ║
  46. ║          │ Greenwich Mean Time (GMT). A positive           │              ║
  47. ║          │ number denotes a time zone west of              │              ║
  48. ║          │ Greenwich and a negative number denotes a       │              ║
  49. ║          │ time zone east of Greenwich.                    │              ║
  50. ║──────────┼─────────────────────────────────────────────────┼──────────────║
  51. ║DDD       │ Daylight Saving Time (DST) time zone            │ EDT          ║
  52. ║          │ identifier. This must be 3 characters,          │              ║
  53. ║          │ must begin with a letter and can contain        │              ║
  54. ║          │ spaces.                                         │              ║
  55. ║──────────┼─────────────────────────────────────────────────┼──────────────║
  56. ║sm        │ Starting month (1 to 12) of DST.                │ 4            ║
  57. ║──────────┼─────────────────────────────────────────────────┼──────────────║
  58. ║sw        │ Starting week (-4 to +4) of DST.                │ 1            ║
  59. ║──────────┼─────────────────────────────────────────────────┼──────────────║
  60. ║sd        │ Starting day of DST                             │ 0            ║
  61. ║          │ 1 to 31 if sw = 0                               │              ║
  62. ║          │ 0 to 6 if sw ¬= 0                               │              ║
  63. ║──────────┼─────────────────────────────────────────────────┼──────────────║
  64. ║st        │ Starting time (in seconds from midnight)        │ 3600         ║
  65. ║          │ of DST.                                         │              ║
  66. ║──────────┼─────────────────────────────────────────────────┼──────────────║
  67. ║em        │ Ending month (1 to 12) of DST.                  │ 10           ║
  68. ║──────────┼─────────────────────────────────────────────────┼──────────────║
  69. ║ew        │ Ending week (-4 to +4) of DST.                  │ -1           ║
  70. ║──────────┼─────────────────────────────────────────────────┼──────────────║
  71. ║ed        │ Ending day of DST                               │ 0            ║
  72. ║          │ 1 to 31 if sw = 0                               │              ║
  73. ║          │ 0 to 6 if sw ¬= 0                               │              ║
  74. ║──────────┼─────────────────────────────────────────────────┼──────────────║
  75. ║et        │ Ending time (in seconds from midnight) of       │ 7200         ║
  76. ║          │ DST.                                            │              ║
  77. ║──────────┼─────────────────────────────────────────────────┼──────────────║
  78. ║shift     │ Amount of time change (in seconds).             │ 3600         ║
  79. ╚═══════════════════════════════════════════════════════════════════════════╝
  80. Thus, the time zone variable is coded as:
  81.     SET TZ=SSS[+|-]nDDD[,sm,sw,sd,st,em,ew,ed,et,shift]
  82.  
  83. As you can see from the table, all the defaults apply to the Eastern Standard Time zone
  84. of the United States.
  85.  
  86. The only sub-parameters that might need further description are the 'sw' and 'ew'
  87. fields. These tell the system whether the starting/ending day for DST is specified as a
  88.                   Switching To/From Daylight Saving Time
  89.  
  90. day of the month or a day of the week within a given week of the month. If the value
  91. for 'sw' or 'ew' is zero then the corresponding 'sd' or 'ed' is a day of the month. If the
  92. value for 'sw' or 'ew' is positive then the corresponding 'sd' or 'ed' is a day of the week
  93. (0=Sunday, 1=Monday,...) and 'sw' and 'ew' define which occurrence of that day of the
  94. week within the month (1=first, 2=second, 3=third, 4=fourth). If the value for 'sw' or
  95. 'ew' is negative then the corresponding 'sd' or 'ed' is a day of the week (as before) and
  96. the 'sw' or 'ew' defines which occurrence of that day of the week reversing from the
  97. end of the month (-1=last, -2=second last, -3=third last, -4=fourth last).
  98.  
  99. How to Start the Program
  100. This program must be in the system at the very instant that switching to or from DST is
  101. to occur. It cannot know when it is started that the clock needed to be changed several
  102. hours or days ago. Thus, it is best that you start the program every time you boot your
  103. machine.
  104.  
  105. If you live outside the U.S. eastern time zone, I suggest that you include in your
  106. CONFIG.SYS a SET statement that establishes your time zone. Since the SET statements
  107. in CONFIG.SYS have not been processed at the time the RUN= statements are
  108. processed, you will need to delay the starting of the program until after CONFIG.SYS
  109. has been fully processed. Hence, you should use the STARTUP,CMD file and place in it
  110. the line
  111.     DETACH x:\directory\DYLTSWCH.EXE
  112. This will create a minimal-resource background process after the TZ variable has been
  113. set.
  114.  
  115. Alternatively, you can place the time zone parameters on the RUN= statement in your
  116. CONFIG.SYS, as follows:
  117.     RUN=x:\directory\DYLTSWCH.EXE GMT0BST,4,1,0,3600,10,-1,0,7200,3600
  118. [Note that the above example is for the British Isles and all other places in the
  119. Greenwich time zone.]
  120.  
  121. What if it breaks?
  122. Any problems or suggestions can be reported to the author, David W. Noon,
  123. via either of two means:
  124.     Compuserve   72172,431   (Internet: 72172.431@compuserve.com)
  125.     FidoNet      David Noon 1:109/347
  126.  
  127. Now you can be asleep at 2:00 AM and still have your computer's clock changed on
  128. time!
  129.