For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > July 2006 > Question on timezone offsets









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Question on timezone offsets
joe@invalid.address

2006-07-15, 6:59 pm

I'm trying to resolve an apparent conflict between Solaris 9 and
FreeBSD 6.1. After calling localtime() the offsets returned have
opposite signs.

#include <stdio.h>
#include <time.h>

#ifdef sun
#define HAVE_DECL_ALTZONE 1
#else
#define HAVE_STRUCT_TM_TM_GMTOFF 1
#endif

#if HAVE_STRUCT_TM_TM_GMTOFF
inline time_t gmtOffset(const struct tm *t){ return t->tm_gmtoff; }
#elif HAVE_DECL_ALTZONE
extern time_t altzone;
inline time_t gmtOffset(const struct tm *t)
{ return (t->tm_isdst == 1) ? altzone : timezone; }
#endif

int main()
{
struct tm tms;
time_t t = time(0);
tms = *localtime(&t);
printf("tms.tm_gmtoff = %d\n", gmtOffset(&tms));
}

Solaris 9 prints 18000, while FreeBSD prints -18000 (I'm in
US/Central).

POSIX says that the offset component of a TZ variable value is east of
the Prime Meridian when the it has a negative sign, and west of it
when the sign is positive.

I don't see it define the offset received from localtime() though. I'd
expect it to be as defined for a TZ variable setting, but I can see
why negative would make sense in this case too, since localtime() goes
from UTC to local.

FreeBSD doesn't define the POSIX daylight or timezone variables, and
they have a timezone function which returns a character string, so it
doesn't look like FreeBSD is very standard in this regard.

Does POSIX define this somewhere, or is this in the realm of
implementation dependence?

Thanks

Joe
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com