Converting time historic GMT to local time by specifying a timezone

T

Tharinda

Hi,
I have this problem of converting a set of times (from 2009)
reported in GMT (you may assume this as UTC) to different local times.
Further I have to consider the daylight savings settings applicable at
that time. It seems this is very difficult in c++ since the timezone
information is taken from the environment variable and I cannot find a
thread safe way to set the environment variables.

Is there any way of getting date time converted to local time by
specifying the GMT and the timezone ?

something like convert_to_local(tm *pTime, const char *TZ)

Thanks in advance!

Tharinda
 
G

Goran Pusic

Hi,
        I have this problem of converting a set of times (from 2009)
reported in GMT (you may assume this as UTC) to different local times.
Further I have to consider the daylight savings settings applicable at
that time. It seems this is very difficult in c++ since the timezone
information is taken from the environment variable and I cannot find a
thread safe way to set the environment variables.

Is there any way of getting date time converted to local time by
specifying the GMT and the timezone ?

something like convert_to_local(tm *pTime, const char *TZ)

As far as I know, this is not possible with "standard" C++. I need to
do this (I need to calculate some future local dates for time zones
other than one I am running on), and I use system-provided information
(in my case, Windows). Time zones are less of a problem, but daylight
saving time is a massive PITA, because the way it's computed is
__utterly__ crazy (but unfortunately necessary).

In Windows, DST switch is explainedin terms of "first/last X in Y"
where X is random day of week, Y is random month. According to
information found in Windows, some time zones (Egypt, IIRC), do DST
switch one second before midnight, and there are other sorts of crazy
dates/hours.

Then, with later system versions (Vista+), DST switch is year-
dependent, which only adds to confusion, and in my case simply makes
me aware that I just can't calculate my dates correctly, cause, what's
to prevent authorities to change DST switch moment at any time in
future and invalidate my calculation based on when I think DST switch
shall occur). Therefore, I put up a warning to users about that.

I already feel sorry for you (or, if there is some comprehensive time
library I know not about, perhaps not).

Goran.
 
T

Tharinda

As far as I know, this is not possible with "standard" C++. I need to
do this (I need to calculate some future local dates for time zones
other than one I am running on), and I use system-provided information
(in my case, Windows). Time zones are less of a problem, but daylight
saving time is a massive PITA, because the way it's computed is
__utterly__ crazy (but unfortunately necessary).

In Windows, DST switch is explainedin terms of "first/last X in Y"
where X is random day of week, Y is random month. According to
information found in Windows, some time zones (Egypt, IIRC), do DST
switch one second before midnight, and there are other sorts of crazy
dates/hours.

Then, with later system versions (Vista+), DST switch is year-
dependent, which only adds to confusion, and in my case simply makes
me aware that I just can't calculate my dates correctly, cause, what's
to prevent authorities to change DST switch moment at any time in
future and invalidate my calculation based on when I think DST switch
shall occur). Therefore, I put up a warning to users about that.

I already feel sorry for you (or, if there is some comprehensive time
library I know not about, perhaps not).

Goran.

Thanks Goran for the reply, I am doing this on a solaris box, and I
have this thing called "tzdatabase" (http://www.twinsun.com/tz/tz-
link.htm) which is used by the libc to determine the localtimes. The
problem is the standard methods provided in the time.h header doesn't
take timezone information as parameters, instead they take it from the
environment. The sad thing is I can't make the function calls thread
safe due to this environment variables issue. Only solution that I see
is going through the localtime function implementation and create my
own thread safe version (which takes timezone as an input parameter).
This is very easy to be said than done. ex:-
http://faculty.qu.edu.qa/rriley/cmpt507/minix/localtime_8c-source.html

Tharinda
 
P

peter koch

As far as I know, this is not possible with "standard" C++. I need to
do this (I need to calculate some future local dates for time zones
other than one I am running on), and I use system-provided information
(in my case, Windows). Time zones are less of a problem, but daylight
saving time is a massive PITA, because the way it's computed is
__utterly__ crazy (but unfortunately necessary).

In Windows, DST switch is explainedin terms of "first/last X in Y"
where X is random day of week, Y is random month. According to
information found in Windows, some time zones (Egypt, IIRC), do DST
switch one second before midnight, and there are other sorts of crazy
dates/hours.

Then, with later system versions (Vista+), DST switch is year-
dependent, which only adds to confusion, and in my case simply makes
me aware that I just can't calculate my dates correctly, cause, what's
to prevent authorities to change DST switch moment at any time in
future and invalidate my calculation based on when I think DST switch
shall occur). Therefore, I put up a warning to users about that.

I already feel sorry for you (or, if there is some comprehensive time
library I know not about, perhaps not).

Goran.

Not only that - you also need knowledge about leap-seconds.

/Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,928
Messages
2,570,068
Members
46,513
Latest member
JacklynMcC

Latest Threads

Top