On 10 April 2017 at 11:38, Ward, Mike S <[email protected]> wrote:
> Hello, list friends. I was wondering if one of you could give me a little
help with a time problem that I have not been able to solve. I have the
need to provide the number of seconds since 1970 for a project that I'm
working on. I have been using a combination of the STCK and the CONVTOD to
try and get the results, but I'm just not that good at math or time
functions. If someone could steer me in the right direction I would really
appreciate it.

Hi Mike,

If you want to have truly accurate results, including all the leap seconds
baggage (Hi Gil), you will need to dig a bit deeper. If you don't mind
being potentially off by a second or three, here is some code I wrote about
20 years ago that works, and shows what you need to do. The result is left
in R14.

         STCK  DWORD               S/370 clock in IBM TOD units (bit 51 = 1
uS)
         LM    R14,R15,DWORD       TOD CLOCK UNITS in R14,R15
         SRDL  R14,12              MICROSECONDS SINCE JAN 1, 1900
         SL    R15,=FL8'2208902400000000'+4 - RIGHT HALF of conversion
factor
         BC    11,*+6              BRANCH ON NO BORROW
         BCTR  R14,R0              -1 FOR BORROW
         SL    R14,=FL8'2208902400000000' - LEFT HALF of conversion factor
         D     R14,=F'1000000'     SECONDS SINCE JAN 1, 1970
         ...
DWORD    DS    D

This was written before zArch and its 64-bit registers, so it does a 64-bit
calculation using 32-bit registers. Still works fine, of course, but could
be shortened. That magic number 2208902400000000 is the conversion factor,
in microsoeconds, between 1900 and 1970.

Of course the value in DWORD doesn't have to come directly from STCK. It
can as well be a stored value, but take care that it's not before 1970...

Tony H.

Reply via email to