Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Converting time historic GMT to local time by specifying a timezone

Reply
Thread Tools

Converting time historic GMT to local time by specifying a timezone

 
 
Tharinda
Guest
Posts: n/a
 
      08-25-2010
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
 
Reply With Quote
 
 
 
 
Goran Pusic
Guest
Posts: n/a
 
      08-25-2010
On Aug 25, 3:10*pm, Tharinda <tharinda...@gmail.com> wrote:
> 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.
 
Reply With Quote
 
 
 
 
Tharinda
Guest
Posts: n/a
 
      08-25-2010
On Aug 25, 7:35*pm, Goran Pusic <gor...@cse-semaphore.com> wrote:
> On Aug 25, 3:10*pm, Tharinda <tharinda...@gmail.com> wrote:
>
> > 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.


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/cmpt...8c-source.html

Tharinda
 
Reply With Quote
 
peter koch
Guest
Posts: n/a
 
      08-25-2010
On 25 Aug., 16:35, Goran Pusic <gor...@cse-semaphore.com> wrote:
> On Aug 25, 3:10*pm, Tharinda <tharinda...@gmail.com> wrote:
>
> > 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.


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

/Peter
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get uclibc style timezone string (e.g GMT+0IST-1,M3.5.0/01:00:00,M10.5.0/02:00:00)from javascript Rohit Javascript 6 07-03-2008 12:03 PM
getmtime in 2.5 reports GMT instead of local time Josef Dalcolmo Python 1 05-03-2007 10:50 PM
Convert GMT to Local Time ZR C Programming 2 03-17-2007 01:14 AM
Convert windows TimeZone to Java TimeZone asaf Java 3 09-11-2006 05:40 PM
GMT time to local time, according to timezone and summer/winter time. David Joseph Bonnici Perl Misc 1 05-15-2005 09:15 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57