utcToLocalTime and daylight saving

For questions and postings not covered by the other forums
ascribe
Posts: 16
Joined: Mon Sep 14, 2009 1:51 pm
Location: Australia
Contact:

utcToLocalTime and daylight saving

Postby ascribe » Mon Oct 22, 2012 1:04 pm

utc := ('21 May 2012, 15:04:43').TimeStamp;
write utc;
write utc.utcToLocalTime;

Assume the value I got for my utc attribute was from app.getUTCTime back in May. The above codes gave me

21 May 2012, 15:04:43
22 May 2012, 02:04:43

I live in Melbourne daylight saving has been started and the current time zone offset is UTC +11 hours. the above output is right if the month is October.

My question is does the method utcToLocalTime includes/excludes daylight saving automatically? And does it include/exclude daylight saving based on when/where it is called?

Thanks for any help.

Cheers

User avatar
BeeJay
Posts: 312
Joined: Tue Jun 30, 2009 2:42 pm
Location: Christchurch, NZ

Re: utcToLocalTime and daylight saving

Postby BeeJay » Tue Oct 23, 2012 8:43 am

The utcToLocalTime method uses the current timezone offset to do the conversion, not the timezone offset that would have been in force on the date in question for your locale. This is the standard behaviour of the underlying windows routines used to do the conversion. The behaviour of these standard windows routines are the subject of much debate on the Internet about what is/isn't the right/wrong way to handle these conversions.

Note: In later releases of Windows, Microsoft have now provided a new conversion routine, SystemTimeToTzSpecificLocalTime, which "does" take into account what DST rules were applicable for that locale on that date/time. If this is important to your application, and you can guarantee all your users will be using recent enough versions of Windows, you may be able to utilise this routine to suit your application requirements.

Cheers,
BeeJay.

allistar
Posts: 156
Joined: Fri Aug 14, 2009 11:02 am
Location: Mount Maunganui, Tauranga

Re: utcToLocalTime and daylight saving

Postby allistar » Tue Oct 23, 2012 9:08 am

We have had to do exactly as BeeJay suggests - go straight to the Windows API via external function calls. The current behaviour is quite counter-intuitive. Let me know if you want the snippet of C++ code that makes this happen (from my understanding there's not much of it).

ascribe
Posts: 16
Joined: Mon Sep 14, 2009 1:51 pm
Location: Australia
Contact:

Re: utcToLocalTime and daylight saving

Postby ascribe » Tue Oct 23, 2012 11:21 am

Thank you for your suggestions guys.

Allista, can you please show me where can I get that c++ snippet,

I haven't used external method before, I am going through the Jade manual right now. If you have some spare times would you please write a few lines of how to call c++ snippet from Jade. Thanks again for your help.

Cheers.

allistar
Posts: 156
Joined: Fri Aug 14, 2009 11:02 am
Location: Mount Maunganui, Tauranga

Re: utcToLocalTime and daylight saving

Postby allistar » Tue Oct 23, 2012 1:29 pm

Hi there,
The C++ external function for converting UTC to local time (taking into account the correct timezone offset for the local time) is:

Code: Select all

extern "C" __declspec(dllexport) int LocalToUtcTime(LPSYSTEMTIME localTime, LPSYSTEMTIME utcTime) { if (TzSpecificLocalTimeToSystemTime(NULL, localTime, utcTime)) return 1; else return 0; }
Calling this from JADE is via an external function:

Code: Select all

localToUtcTime(localTimeIn : Binary[256] input; utcTimeOut : Binary[256] output): Integer is LocalToUtcTime in libraryName presentationClientExecution;
Example JADE code calling this is:

Code: Select all

binLocalTime := date.year.Binary[1:2] & date.month.Binary[1:2] & 0.Binary[1:2] & date.day.Binary[1:2] & time.hour.Binary[1:2] & time.minute.Binary[1:2] & time.second.Binary[1:2] & time.milliSecond.Binary[1:2]; result := call localToUtcTime(binLocalTime, binUTCTime);
Regards,
Allistar.


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 24 guests