On 11/22/2011 12:40 PM, James Lampert wrote:
That is SLICK! I thought I'd come up with a simple solution (SUBDUR),
but this is even better (and doesn't require the time zone to be either
hardcoded or explicitly retrieved).
Dennis is calling the time() API, which has been a standard API on Unix
forever. But he seems to have added some extra code that I don't
understand the purpose for. I would expect it to be as simple as this:
H DFTACTGRP(*NO) BNDDIR('QC2LE')
D time pr * extproc('time')
D tloc 10i 0
D my_secs s 10i 0
/free
time(my_secs);
dsply (%char(my_secs) + ' seconds since Jan 1, 1970.');
*inlr =*on;
/end-free
Thanks. About the only thing mine has to recommend it is that it works
in the default activation group, which isn't really a factor, since
yours will also work with ACTGRP(*CALLER), if necessary.
If you're worried about ACTGRP, consider making the above a standalone
program, and running it in something like ACTGRP(QILE). Then the
calling programs can all be in *DFTACTGRP if you want them to be.
I do not recommend coding the above in ACTGRP(*CALLER) -- unless you
know it'll never be called from *DFTACTGRP. Loading that code into the
*DFTACTGRP via *CALLER is just asking for trouble -- and it's totally
unnecessary.
It might be worth noting that this API (as coded) is expected to stop
working in the year 2038, as that's when there will be so many seconds
they don't fit in the 10i 0 variable. Many Unix systems have changed
the result of time() to be unsigned, so it'll run longer... but it
doesn't look like IBM has done this.
But, even if you didn't know C or Unix, and didn't know about the time()
API, I can't see why you'd retrieve the timezone, et al... wouldn't you
just call the CEEUTC API? (OR CEELOCT for local?)
As an Amazon Associate we earn from qualifying purchases.