Time Zone


the Time Conversion Zone.”

Listing 1

Private 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

Private Type TIME_ZONE_INFORMATION_REG
Bias As Long
StandardBias As Long
DaylightBias As Long
StandardDate As SYSTEMTIME
DaylightDate As SYSTEMTIME
End Type

Private Type TIME_ZONE_INFORMATION
Bias As Long
StandardName As String * 64
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName As String * 64
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type

Private Declare Sub CopyMemory Lib _
“kernel32” Alias “RtlMoveMemory” (lpvDest As Any, _
lpvSource As Any, ByVal cbCopy As Long)

Private Declare Function GetTimeZoneInformation Lib “kernel32” _
(lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long

Listing 2

Private Function DateFromSYSTEMTIME _
(aSYSTEMTIME As SYSTEMTIME, _
Optional iRefYear As Integer) As Variant

‘Returns either a Date or Null using values in
‘SYSTEMTIME structure

With aSYSTEMTIME
If .wDay = 0 And .wDayOfWeek = 0 And _.wHour = 0 And _
.wMilliseconds = 0 And .wMinute = 0 And .wMonth = 0 And _
.wSecond = 0 And .wYear = 0 Then

‘all structure fields contain 0 indicating invalid date
DateFromSYSTEMTIME = Null
Else
If .wYear = 0 Then
‘day-in-month format; uses wMonth, wDayOfWeek,
‘wDay to identify a specific occurance of
‘a weekday in that month. The year is specified by
‘iRefYear or the current year.

‘if no year passed in, use current year
If iRefYear = 0 Then iRefYear = Year(Date)

DateFromSYSTEMTIME = _
WeekdayOccurance _
(iRefYear, .wMonth, (.wDayOfWeek + 1), _
.wDay) + TimeSerial(.wHour, .wMinute, _
.wSecond)
Else
‘absolute format; includes year
DateFromSYSTEMTIME = _
DateSerial(.wYear, .wMonth, .wDay) + _
TimeSerial(.wHour, .wMinute, .wSecond)
End If
End If
End With
End Function

Listing 3

Public Sub Refresh()

‘Fills time zone information from registry and/or api call

Dim strTimeZoneKey As String
Dim vRet As Variant
Dim bytArray() As Byte
Dim tziTimeZoneInfoStruct As _
TIME_ZONE_INFORMATION
Dim oSystem As New CSystem
Dim objRegKey As RegKey
Dim sKey As String

If mlngID = tzcTimeZoneSystem Then
‘get current system time zone settings
vRet = GetTimeZoneInformation(tziTimeZoneInfoStruct)
With tziTimeZoneInfoStruct
mstrStandardShortName = StripNull(StrConv( _
.StandardName, vbFromUnicode))
mstrDaylightShortName = StripNull(StrConv( _
.DaylightName, vbFromUnicode))
mtzrTimeZoneInfoRegistryStruct.Bias = .Bias
mtzrTimeZoneInfoRegistryStruct.DaylightBias = _
.DaylightBias
mtzrTimeZoneInfoRegistryStruct.DaylightDate = _
.DaylightDate
mtzrTimeZoneInfoRegistryStruct.StandardBias = _
.StandardBias
mtzrTimeZoneInfoRegistryStruct.StandardDate = _
.StandardDate
End With

mlngID = GetIDFromShortName(mstrStandardShortName)
strTimeZoneKey = GetTimeZoneRegKeyFromID(mlngID)
If Len(strTimeZoneKey) > 0 Then

If oSystem.Platform = emsOSPlatformWindowsNT Then
sKey = TZ_REG_KEY_NT & strTimeZoneKey
Else
sKey = TZ_REG_KEY_95 & strTimeZoneKey
End If

Set objRegKey = RegKeyFromString( _
“\HKEY_LOCAL_MACHINE\” & sKey)

‘ DisplayName is not returned in TIME_ZONE_INFORMATION
‘ structure, read from registry
mstrDisplayName = objRegKey.Values.Item( _
“Display”).Value
End If

Else
‘get specified time zone from registry

strTimeZoneKey = GetTimeZoneRegKeyFromID(mlngID)
If Len(strTimeZoneKey) > 0 Then

If oSystem.Platform = emsOSPlatformWindowsNT Then
sKey = TZ_REG_KEY_NT & strTimeZoneKey
Else
sKey = TZ_REG_KEY_95 & strTimeZoneKey
End If

Set objRegKey = RegKeyFromString( _
“\HKEY_LOCAL_MACHINE\” & sKey)
mstrDisplayName = objRegKey.Values.Item( _
“Display”).Value
mstrDaylightShortName = objRegKey.Values.Item( _
“Dlt”).Value
mstrStandardShortName = objRegKey.Values.Item( _
“Std”).Value

vRet = objRegKey.Values.Item(“TZI”).Value

If IsEmpty(vRet) Then
Err.Raise vbObjectError, , _
“Registry key or value not valid.”
End If

bytArray = vRet
‘assigns byte array in variant to dynamic byte array

‘copy bytes into appropriate structure locations
CopyMemory mtzrTimeZoneInfoRegistryStruct, _
bytArray(0), Len(mtzrTimeZoneInfoRegistryStruct)

End If
End If

‘if the wMonth entry is 0 then time zone doesn’t support
‘daylight savings and therefore will not have values for
‘StandardDate and DaylightDate

If mtzrTimeZoneInfoRegistryStruct.StandardDate.wMonth _
= 0 Then
mbolSupportDaylight = False
Else
mbolSupportDaylight = True
End If
End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s