NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: question about strptime on NetBSD 6 stable

Christos Zoulas <> wrote ..
> In article <>,
> Waitman Gobble <> wrote:
> >
> >It seems like strptime is ignoring %z on NetBSD 6 stable? Or maybe i'm
> >doing it wrong.
> mktime(3) uses the "local time" to convert struct tm * to time_t. This
> means that while strptime(3) takes into account the tzoffset and sets
> tm->tm_gmtoff correctly, this field is not taken into account by mktime(3)
> since doing so would violate the standard. Depending on the timezone you
> have set, you are going to see different results; perhaps this is why you
> think that the other OS is correct :-)
> NetBSD provides extensions such as mktime_z() that control which timezone
> is used on a call by call basis, instead of relying on the environment.
> christos

After looking through the src I think I see what's going on... 

The man page for mktime seems to read that it uses the TZ environment variable, 
however changing the TZ environment variable did not change the output of my 
sample test program.
the source...
The way mktime is defined, it is actually calling mktime_z and using the TZ set 
in the tm struct. So when I use strptime it's parsing the %Z, mktime is 
actually calculating the result using the offset provided in the tm structure. 


mktime(struct tm * const        tmp)
        time_t result;

        result = mktime_z(lclptr, tmp);
        return result;

ref: symlink to export /usr/src on this machine:

So I think if I want mktime to return a time 'relative' to a timezone i just 
change the TZ value in the tm struct before the call??? Does that sound correct?

I am guessing that the 'other' BSD system doesn't do it like that, and instead 
uses TZ in the environment, which is how the man page reads.??? I'll have to go 
look at the source code.

Thank you,

Waitman Gobble
San Jose California USA

Home | Main Index | Thread Index | Old Index