On 21/07/2017 1:11 AM, Kirk Wolf wrote:
As usual, the knowledge and helpfulness of those on this list is
astonishing.
I'm actually writing this in Java (to 64-bit java "long" epoch seconds,
from both STCK and STCKE inputs), but the sample IBM assembler code
initially puzzled me.
I had to do just that recently to convert a STCK to a Java 8 date/time
Instance. Java Instances support nano-second precision so I factored
that in. I didn't do STCKE inputs which is a bit shorted sighted. I'll
add that to the backlog.
The Java date/time library is excellent. The Java languages lack of
unsigned types isn't.
Probably not optimal, suggestions welcome.
/**
* This class provides factory methods for creating various Java date/time
* objects from zArchitcture <code>STCK</code> Store Clock units.
*
* Store Clocks are 64-bit integer values which provide a high resolution
* measure of real time suitable for the indication of date and time of
day.
* See the Timing chapter in Principles of Operation for details:
* http://publibfp.boulder.ibm.com/epubs/pdf/dz9zr010.pdf
*/
public class StoreClock {
/** Constant for the start of the POSIX epoch in nano-seconds */
public static final long POSIX_EPOCH_OFFSET_NANO = 0x1EA7E79C20D10000L;
/** Constant for the start of the POSIX epoch in micro-seconds */
public static final long POSIX_EPOCH_OFFSET_MICRO = 0x7D91048BCA000L;
/** Constant for the clock unit for a leap year */
public static final long TOD_UNIT_LEAP_YEAR = 0x1CC2A9EB4000000L;
/** Constant for the clock unit for a year */
public static final long TOD_UNIT_YEAR = 0x1CAE8C13E000000L;
/** Constant for the clock unit for a day */
public static final long TOD_UNIT_DAY = 0x141DD7600000L;
/** Constant for the clock unit for an hour */
public static final long TOD_UNIT_HOUR = 0xD693A400000L;
/** Constant for the clock unit for a minute */
public static final long TOD_UNIT_MIN = 0x3938700000L;
/** Constant for the clock unit for a second */
public static final long TOD_UNIT_SEC = 0xF4240000L;
/** Constant for the clock unit for a milli-second */
public static final long TOD_UNIT_MILLIS = 0x3E8000L;
/** Constant for the clock unit for a micro-second */
public static final long TOD_UNIT_MICROS = 0x1000L;
/**
* Obtains an instance of <code>Instance</code> from a Store Clock. The
* resulting <code>Instance</code> is in UTC time with nano-second
precision.
*
* @param stck A Store Clock value
*
* @return The <code>Instant</code>, no null.
*/
public static Instant getInstant(long stck) {
long epochMicro = stck >>> 12; // convert to micro-seconds
long epochNano = epochMicro * 1000; // and to nano-seconds
long nanoSecs = stck % 4096; // get the remainder
nano-seconds in TOD units
epochNano += nanoSecs * 1000 / 4096; // convert to nano-seconds
and add to the epoch
epochNano -= POSIX_EPOCH_OFFSET_NANO; // convert to the POSIX epoch
long epochSecs = epochNano / 1000_000_000L; // number of seconds
from the epoch
nanoSecs = epochNano % 1000_000_000L; // remainder nano-seconds
return Instant.ofEpochSecond(epochSecs, nanoSecs);
}
/**
* Obtains an instance of <code>Instance</code> from a Store Clock. The
* resulting <code>Instance</code> is in UTC time with nano-second
precision.
*
* @param stck A byte array containing a Store Clock value
*
* @return The <code>Instant</code>, no null.
*/
public static Instant getInstant(byte[] stck) {
return getInstant(ByteBuffer.wrap(stck).getLong());
}
/**
* Obtains an instance of <code>ZonedDateTime</code> from a Store
Clock. The
* time is calculated using the time zone offset and leap second
offset clock
* units.
*
* @param stck A Store Clock value
* @param zoneOffset The time zone offset in TOD units.
* @param leapSecondOffset The leap second offset in TOD units..
*
* @return The <code>ZonedDateTime</code>, no null.
*/
public static ZonedDateTime getZonedDateTime(long stck, long
zoneOffset, long leapSecondOffset) {
int offset = (int)(zoneOffset / TOD_UNIT_SEC);
return ZonedDateTime.ofInstant(getInstant(stck - leapSecondOffset),
ZoneOffset.ofTotalSeconds(offset));
}
Kirk Wolf
Dovetailed Technologies
http://dovetail.com
PS> (I don't write much assembler any more); here's an ordering of my
ability to understand assembler code, ranked by source:
- good assembler programmer
- XLC/C++ compiler
- IBM sample code in a manual
- bad assembler programmer
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN