timezone

Hi.

I have the following settings for the TZ variable.

TZ=est05edt04,M4.1.0/2,M10.5.0/2

I checked out the timezone variable from c code and the value is 18000.
Why? I expected to see 14400.

When I print out time using the ctime() and asctime() functions there is a 4
hour difference as expected.

TIA

Augie

Augie Henriques <augiehenriques@hotmail.com> wrote:

Hi.

I have the following settings for the TZ variable.

TZ=est05edt04,M4.1.0/2,M10.5.0/2

I checked out the timezone variable from c code and the value is 18000.
Why? I expected to see 14400.

I’m not sure that isn’t correct. The definition for timezone states
that it is “the number of seconds of time that the local time zone is
earlier than Coordinated Universal Time (UTC)”.

Our TIME ZONE is EST. 5 hours. Daylight savings is not, I think, actually
a different time zone, just a further modifier on our timezone.

-David

QNX Training Services
dagibbs@qnx.com

“David Gibbs” <dagibbs@qnx.com> wrote in message
news:9nb3i7$inp$1@nntp.qnx.com

Augie Henriques <> augiehenriques@hotmail.com> > wrote:
Hi.

I have the following settings for the TZ variable.

TZ=est05edt04,M4.1.0/2,M10.5.0/2

I checked out the timezone variable from c code and the value is 18000.
Why? I expected to see 14400.

I’m not sure that isn’t correct. The definition for timezone states
that it is “the number of seconds of time that the local time zone is
earlier than Coordinated Universal Time (UTC)”.

Our TIME ZONE is EST. 5 hours. Daylight savings is not, I think,
actually
a different time zone, just a further modifier on our timezone.

David,

How do I determine the current UTC offset in seconds, taking into account
all the settings?

Augie

-David

QNX Training Services
dagibbs@qnx.com

Augie Henriques <augiehenriques@hotmail.com> wrote:


David,

How do I determine the current UTC offset in seconds, taking into account
all the settings?

I don’t see a clean way to get that information. (I can see ugly
ways having to do with getting a localtime, then clearing the TZ
environment variable, then…, but no clean way.)

Well, if you know what your locale’s offset for DST is, you could
get the time, then do a localtime(), and look at the tm_isdst
flag to see if DST is in effect, then do the math. But, if you
don’t know where this code will be run, then this may be problematic.
(Unless DST is always defined as one hour, but I don’t think it has
to be.)

Maybe someone else will have a better suggestion…

-David

QNX Training Services
dagibbs@qnx.com

Here you go:
/*

Return the number of seconds that the local time is EARLIER

that Coordinated Universal Time (UTC) (also know as GMT time)

*/

time_t GetTimeZone (void)
{

time_t today_time;

struct tm gmtime_tm;

struct tm localtime_tm;

time (& today_time);

_gmtime ( & today_time, &gmtime_tm);

_localtime ( & today_time, &localtime_tm);


gmtime_tm.tm_isdst = localtime_tm.tm_isdst;

return ( mktime ( &gmtime_tm) - mktime (&localtime_tm) );
}

  • Cesar H.

“David Gibbs” <dagibbs@qnx.com> wrote in message
news:9nb917$lbp$1@nntp.qnx.com

Augie Henriques <> augiehenriques@hotmail.com> > wrote:


David,

How do I determine the current UTC offset in seconds, taking into
account
all the settings?

I don’t see a clean way to get that information. (I can see ugly
ways having to do with getting a localtime, then clearing the TZ
environment variable, then…, but no clean way.)

Well, if you know what your locale’s offset for DST is, you could
get the time, then do a localtime(), and look at the tm_isdst
flag to see if DST is in effect, then do the math. But, if you
don’t know where this code will be run, then this may be problematic.
(Unless DST is always defined as one hour, but I don’t think it has
to be.)

Maybe someone else will have a better suggestion…

-David

QNX Training Services
dagibbs@qnx.com