Daylight Saving Time

Ken Ray kray at sonsothunder.com
Tue Oct 28 01:29:19 EDT 2008


OK, here's the "tools" to get whether DST is in effect on the current
machine (and also how to get at the "guts" of time zone data) - my code is
too intertwined with other things in my library to extract all the relevant
handlers, but here's the bottom line (returned values are all relevant to my
system):

Mac:

  1) Get the local time zone:

          put word -1 of shell("ls -l /etc/localtime")
          --> /usr/share/zoneinfo/US/Central

  2) Get the time period for the current time zone you're currently in by
executing:

      put shell("date '+%Z'")
      --> CDT

  3) Grab the list of all the time ranges available for your time zone:

          put shell("zdump -v /etc/localtime")
          --> /etc/localtime  Fri Dec 13 20:45:52 1901 UTC = Fri Dec 13
14:45:52 1901 CST isdst=0
             (etc.)

      There's a bunch of lines, one for CST and one for CDT, with the
"isdst" equal to zero if DST is not in effect, or equal to 1 if DST is in
effect.

  4) Look down the list to find the year (word 6 of the line) that is the
current year, and see what the current time is in the time range, with the
proper time period, then check the "isdst" to see if it's a 0 or 1.

Windows:

  1) Execute this VBScript:

strComputer = "."
retVal = ""
Set objWMIService = GetObject("winmgmts:\\" & strComputer & _
    "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TimeZone")
For Each objItem in colItems
  retVal = retVal & objItem.Description & vbCrLf
  retVal = retVal & objItem.Bias & vbCrLf
  retVal = retVal & objItem.DaylightName & vbCrLf
  retVal = retVal & objItem.DaylightMonth & "," & objItem.DaylightDay & _
    "," & objItem.DaylightHour & "," & objItem.DaylightMinute & _
    "," & objItem.DaylightSecond & "," & objItem.DaylightDayOfWeek & vbCrLf
  retVal = retVal & objItem.DaylightBias & vbCrLf
  retVal = retVal & objItem.StandardName & vbCrLf
  retVal = retVal & objItem.StandardMonth & "," & objItem.StandardDay & _
    "," & objItem.StandardHour & "," & objItem.StandardMinute & _
    "," & objItem.StandardSecond & "," & objItem.StandardDayOfWeek & vbCrLf
  retVal = retVal & objItem.StandardBias & vbCrLf
  retVal = retVal & objItem.Caption
Next
Wscript.Echo retVal
 
(For Rev 3 and higher use "result = retVal" instead of "Wscript.Echo
retVal".)

2) Check line 5 of the result - if it's "0", you are definitely not
experiencing DST. If it's not zero, you need to check the current date to
see if it falls within the Daylight time period (line 4 of the result). BTW:
Keep in mind that for the "DaylightDayOfWeek", VB is 0-based, so day "0" is
Sunday...

Whew!

As far as I know, this is the most accurate method of getting time zone info
from Mac and Windows systems - it's a PITA and requires a lot of parsing,
and if anyone has a better/easier way of doing it, PLEASE let me know! (And
the list of course... ;-)


Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/





More information about the use-livecode mailing list