On 2019-08-19 12:41 AM, Paul Gilmartin wrote:
I once wrote some C code that sets the TZ, _TZ variables from the time
zone offset, leap second offset values in the CVT.
    ...
   // set the time zone offset and apply the leap second offset
   int64_t ldto = cvt->cvtext2->cvtldto - cvt->cvtext2->cvtlso + adjust;

Is this intended to be used with localtime() and strftime()?  Localtime()

Yes, and it works perfectly :)

expects time() to have accounted for leap seconds, so they should not
appear in TZ.  An example on Linux (TZ value simulated by hand):
     510 $ TZ=Asia/Calcutta date; TZ=GMT-5:29:33 date
     Sun Aug 18 21:45:02 IST 2019
     Sun Aug 18 21:44:35 GMT 2019

My code is intended to be run in environments where the TZ environment variable has not been set. As it works as expected I'm not sure
that time() has accounted for leap seconds.

... I claim the former is correct.  Also, the zone name, GMT, is wrong.
Correct is IST.

Does IST work on z/OS?

       ...
     // if minutes have been specified then calculate them
     uint64_t mins = ldto % STCK_UNIT_HOUR;
( My C skill fails me.  What kind of statement is that?  An assignment?
I'd not expect two tokens left of "=".  A cast?  I'd expect "( ... )", and
a cast has no L-value.  A declaration with initialization?  It would be out
of place. )

compile it using C99:

    c99 -o settimezone settimezone.c


What happens if a DST transition, or even a leap second, occurs between
such a setting of TZ and your program's formatting of current time?

For our purposes we don't need to be that robust so we don't care :)

    ...
   setenv("TZ", tzone, 1);   // for POSIX
   setenv("_TZ", tzone, 1);  // for non-POSIX


----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to