Tech Support Guy banner
Status
Not open for further replies.
1 - 1 of 1 Posts

·
Registered
Joined
·
107 Posts
Discussion Starter · #1 ·
Yes, it's that time of year again...change batteries in the smoke detectors, and fix all of my programs because we've changed to Daylight Savings Time.
My programs collect weather data from all over the US and must make calculations based upon the time zones for each area. Also, the program is used by others in different time zones and those variances must be accounted for. Therefore, it is important to have the system's UTC (or UTM or GMT) and the correct time difference (bias) known.
I thought I had the problem licked when I added the code below. Simple, run the code, get the current time zone, standard or daylight, get the offsets (standard bias and daylight bias) and the total offset (bias) which I thought was the combined standard bias and daylight bias.
I am in the Eastern Time zone so my offset during Standard time is -5 hours (-300 minutes) and during Daylight savings, -4 hours (-240 minutes).
The code below correctly identifies the the system's time zone and whether or not daylight savings is in effect, and it correctly identifies the .daylightbias (60). But, the .bias always comes up as -300 (in my time zone) irregardles of Daylight savings or not, and the .standardbias is alway 0.
QUESTIONS: Should not the .standardbias be -300 and the .bias be the sum of the .standardbias and .daylightbias (-240)? Is there another result which gives me the the actual total time offset that the system is using? Should I just say what you see is what you get, and if Daylight savings is TRUE, add the .daylightbias to the .bias and ignore the standard bias?

Sorry about being so long, but any help is appreciated. I need to update all of these programs pretty soon.
Thanks, Tom


Option Explicit
Const TIME_ZONE_ID_UNKNOWN As Long = 1
Const TIME_ZONE_ID_STANDARD As Long = 1
Const TIME_ZONE_ID_DAYLIGHT As Long = 2
Const TIME_ZONE_ID_INVALID As Long = &HFFFFFFFF

Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type

Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(0 To 63) As Byte 'Unicode
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(0 To 63) As Byte 'Unicode
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type

Declare Function GetTimeZoneInformation Lib "kernel32" _
(lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long


Function SystemTZ()
Dim lRV As Long
Dim dRV As Date
Dim tzi As TIME_ZONE_INFORMATION
Dim tmp(8) As String
Dim X As Integer
lRV = GetTimeZoneInformation(tzi)
Select Case lRV
Case 0: tmp(0) = "Cannot determine current time zone"
tmp(1) = "NONE"
Case 1: tmp(0) = tzi.StandardName
tmp(1) = "NO"
Case 2: tmp(0) = tzi.DaylightName
tmp(1) = "YES"
End Select
If InStr(tmp(0), Chr$(0)) Then tmp(0) = Left(tmp(0), InStr(tmp(0), Chr$(0)))
tmp(3) = tzi.Bias '/ -60
tmp(4) = tzi.StandardBias
tmp(5) = tzi.DaylightBias ' / -60
tmp(6) = DateAdd("n", CDbl(tzi.Bias), Now)
tmp(7) = Now()
SystemTZ = DateAdd("n", CDbl(tzi.Bias), Now)
End Function
 
1 - 1 of 1 Posts
Status
Not open for further replies.
Top