Home Back to 370 Assembler Tips & Tricks Index Links

Convert UTC or GMT STCK to Local Time

STCK format date and time values are often either synchronized to UTC (Universal Coordinated Time) or GMT (Greenwich Mean Time).  UTC has a fixed length second that is periodically corrected by inserting leap seconds, while GMT has a variable length second.  For more information regarding the differences between UTC and GMT refer to the z/Architecture Principles of Operation.

The z/OS operating system maintains the Time Zone and Leap Second offsets in the OS/VS2 Common CVT Extension control block.  In order to convert a UTC STCK value or a GMT STCK value to a local time STCK value, one must apply these offset values to STCK value.

Here's the first code snippet of two illustrating a technique that will convert either UTC or GMT to Local time:

 


           .
           .
           .
         L     R1,CVTPTR           Load A(CVT).
         USING CVT,R1              Establish CVT addressability.
*
         L     R1,CVTEXT2          Load A(CVT Extension).
         DROP  R1                  Drop CVT.
*
         USING CVTXTNT2,R1         Establish Ext. addressability.
*
         STCK  STCKTOD             Store current UTC/GMT clock value.
         LM    R2,R3,STCKTOD       Load clock Hi and Lo words.
         LM    R4,R5,CVTLDTO       Load offset Hi and Lo words.
         ALR   R3,R5               Add Lo word time offset.
         ALCR  R2,R4               Add w/Carry Hi word offset.
*
*        CVTLSO High and Low words should both be zero if the clock
*        is synchronized to GMT so the following instructions will
*        only have an effect if the clock is synchronized to UTC.
*
         LM    R4,R5,CVTLSO        Load leap sec Hi and Lo words.
         DROP  R1                  Drop CVT Extension.
*
         SLR   R3,R5               Sub Lo word leap seconds.
         SLBR  R2,R4               Sub w/Borrow Hi word leap secs.
         STM   R2,R3,STCKTOD       Store local time clock value.
           .
           .
           .
STCKTOD  DC    FL8'0'              STCK work field.
           .
           .
           .
         CVT   DSECT=YES,LIST=YES  Generate CVT DSECT.
           .
           .
           .

In the above example, we convert either a UTC or GMT 8 byte clock value to a 8 byte local time clock value using 32-Bit registers.

The following code snippet saves a couple of instructions over the previous example by using 64-Bit z/Architecture registers:


           .
           .
           .
         L     R1,CVTPTR           Load A(CVT).
         USING CVT,R1              Establish CVT addressability.
*
         L     R1,CVTEXT2          Load A(CVT Extension).
         DROP  R1                  Drop CVT.
*
         USING CVTXTNT2,R1         Establish Ext. addressability.
*
         STCK  STCKTOD             Store current UTC/GMT clock value.
         LG    R2,STCKTOD          Load 64-Bit clock value.
         LG    R3,CVTLDTO          Load 64-Bit date/time offset value.
         ALGR  R2,R3               Add 64-Bit date/time offset.
*
*        CVTLSO High and Low words should both be zero if the clock
*        is synchronized to GMT so the following instructions will
*        only have an effect if the clock is synchronized to UTC.
*
         LG    R3,CVTLSO           Load 64-Bit leap second offset value.
         DROP  R1                  Drop CVT Extension.
*
         SLGR  R2,R3               Subtract 64-Bit leap second offset.
         STG   R2,STCKTOD          Store 64-Bit local time clock value.
           .
           .
           .
STCKTOD  DC    FL8'0'              STCK work field.
           .
           .
           .
         CVT   DSECT=YES,LIST=YES  Generate CVT DSECT.
           .
           .
           .

If for some reason, no Time Zone offset is used (i.e., the LPAR time is synchronized to local time), both CVTLDTO and CVTLSO will contain zeroes.  If the LPAR time is synchronized to GMT, only CVTLDTO will contain an offset and CVTLSO will contain zeroes.  If the LPAR time is synchronized to UTC, CVTLDTO will contain the time and date offset and CVTLSO will contain the leap second offset.  Thus, both the latter code snippets work regardless how the LPAR time is synchronized.

I will continue to add tips and techniques as time permits.

Please direct any inquiries or problems regarding this web to webmaster@marcsweb.com


Page design, composition and HTML by Marc Niegowski
Copyright © 1998-2012, Marc Niegowski - Connectivity, Inc., All Rights Reserved
23 W. Fourth Street • Media • Pennsylvania • 19063-2805 • USA
Phone: 610-566-0227 • Fax: 610-566-0641 • Email: Marc@Tech-Center.com

Revision Date: Monday, September 17, 2007 04:56:30 PM