Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Will a time in the future need to be adjust for DST? 1

Status
Not open for further replies.

AndyGroom

Programmer
May 23, 2001
972
GB
I have some code for integrating vCalendar files (.ics) into a database. A problem recently arose when a file received on 4th October and which contained an appointment for 30th October was integrated into the database at the wrong time. The appointment was for 10am but was added at 11am because on 4th October we were in BST (British Summer Time) and 30th October is not.

The ics file didn't contain any timezone information and so my app used UTC as the basis for the time of the appointment (times in .ics files are based on UTC). It then got the UTC of local time on the machine with the database and adjusted the appointment time accordingly. I can see now that it's wrong because instead of using local time on the machine it should be using local time as it will be on the 30th October on the machine.

Is it possible to return local time as it will be on a future date?

- Andy
___________________________________________________________________
If a man speaks in a forest and there are no women around to hear him - will he still be wrong?
 
Hmm, yeah I'm already using that API call but as far as I'm aware it returns the system time adjusted to a specific timezone, whereas I'd need it to return a date in the future adjusted to a specific timezone. Or am I looking at this the wrong way?

- Andy
___________________________________________________________________
If a man speaks in a forest and there are no women around to hear him - will he still be wrong?
 
Certainly looks as if you are looking at it the wrong way. I think you are are confusing SystemTime with a SYSTEMTIME. SYSTEMTIME can contain any time you like.

For example:

Code:
[blue]Option Explicit

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

' Shortcut version, working with current process' timezone settings
Private Declare Function SystemTimeToTzSpecificLocalTime Lib "kernel32" (ByVal lpTimeZoneInformation As Long, ByRef lpUniversalTime As SYSTEMTIME, ByRef lpLocalTime As SYSTEMTIME) As Long


Public Sub example() ' Assumes UK is local TZ
    Dim srcST As SYSTEMTIME
    Dim tgtST As SYSTEMTIME
    
    'Populate SYSTEMTIME with UTC in the future
    With srcST
        .wHour = 4
        .wMinute = 15
        .wMonth = 10
        .wDay = 25
        .wYear = 2013
    End With
    
    SystemTimeToTzSpecificLocalTime 0&, srcST, tgtST
    
    With tgtST
        MsgBox DateSerial(.wYear, .wMonth, .wDay) & " " & TimeSerial(.wHour, .wMinute, .wSecond)
    End With
    
    srcST.wDay = 30 ' Move after DST date
    
    SystemTimeToTzSpecificLocalTime 0&, srcST, tgtST
    
    With tgtST
        MsgBox DateSerial(.wYear, .wMonth, .wDay) & " " & TimeSerial(.wHour, .wMinute, .wSecond)
    End With

End Sub[/blue]


 
Yes, thanks!

Public Sub example() ' Assumes UK is local TZ

By passing 0& as lpTimeZoneInformation, does that mean the example always uses the UK's daylight saving times regardless of the user's locality settings? Or hopefully does it mean use the timezone of the locality?


- Andy
___________________________________________________________________
If a man speaks in a forest and there are no women around to hear him - will he still be wrong?
 
>it mean use the timezone of the locality?

Yep. Uses the timezone the process is running under
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top