© peterflass@newsgroup

This program returns Greenwich Mean Time

/* REXX EXEC to get cuttent GMT TOD
   Description: Extracts CVTTZ from the CVT
      (CVTTZ is the difference between local time and GMT).
      The local time obtained from time Time() function
      is adjusted to derive GMT.
      This assumes the system clock is correctly set to GMT
*/
cvtptr = Storage( 00000010, 4 )      /* Get A(CVT) */
cvtptr = Hexstr(cvtptr)
acvttz = D2X( X2D(cvtptr) + X2D('130') ) /*A(CVTTZ)*/
/*
   cvttz is (signed) diff between GMT and local
   time in 1.048576 sec units
   Obviously the following could be simplified
   into one statement ...
*/
cvttz  = Storage( acvttz, 4)       /* Get CVTTZ    */
cvttz  = Hexstr(cvttz)
cvttz  = X2D(cvttz,8)
cvttz  = cvttz * 1.048576
cvttz  = cvttz / 3600              /* Assume whole */
cvttz  = Trunc(cvttz)

Say "Time zone=" cvttz             /* hour diff.   */
localtime = Time()
Parse var localtime hr ':' mn ':' sc
hr = hr - cvttz
If hr<0 Then Do
  hr = 24 + hr
  Say "GMT date is one greater than local date"
  End
If hr!!mn!!sc>"240000" Then Do
  hr = hr - 24
  Say "GMT date is one less than local date"
  End
Say "GMT is" hr':'mn':'sc
Exit

/* Convert binary fullword to Hex character string */
hexstr: Procedure
Arg binword
h0 = substr(binword,1,1)
h1 = substr(binword,2,1)
h2 = substr(binword,3,1)
h3 = substr(binword,4,1)
return(hexchr(h0)!!hexchr(h1)!!hexchr(h2)!!hexchr(h3))

/* Convert binary character to two hex digits */
hexchr: Procedure
Arg char
lo = Bitand(char,'0F'x)
lo = Translate(lo,"0123456789ABCDEF",
                 ,'000102030405060708090A0B0C0D0E0F'x)
ho = Bitand(char,'F0'x)
ho = Translate(ho,"0123456789ABCDEF",
                 ,'00102030405060708090A0B0C0D0E0F0'x)
return(ho!!lo)
back to The Power of REXX