Question on timezone offsets



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
.



Relevant Pages

  • Re: very big files on cd9660 file system
    ... Sizes are 64 bits in the standard, but FreeBSD has always ... This fakes the inode number as the byte offset of the directory entry. ... Since the limit is on the offsets of directory entries, ...
    (freebsd-questions)
  • Re: telldir()/seekdir() confusion
    ... On FreeBSD, seekdir() doesn't seem to behave as I expect ... the first and second telldir() return the same ... filecount past that offset are stored in a linked list (see the ...
    (freebsd-hackers)
  • g_vfs_done() error
    ... Recently I have moved from FreeBSD 6.2 to FreeBSD 7.0. ... lot of error messages like the following: ... The offset seems to be totally wrong, ... sectors/track: 63 ...
    (freebsd-stable)
  • How to do IO across hardsector boundries
    ... FreeBSD to linux. ... getting in trouble regarding the data from offset 0-63 and 64+512->1023? ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Date Time value representation: sign of timezone offset?
    ... Universal Time. ... I just want to be sure that this is indeed the offset that is added to ... UTC to obtain the localtime and not the reverse (add to localtime to ...
    (comp.protocols.dicom)