Guardian Programmer's Guide

Table Of Contents
Managing Time
Guardian Programmer’s Guide 421922-014
18 - 22
A Sample Long-Range Timer
jt = CONVERTTIMESTAMP(jt,0,,&err);
INTERPRETTIMESTAMP(jt,DT);
if (err) printf(" *** error: %d",err);
else
printf(" LCT: %d/%02d/%02d %02d:%02d:%02d.%03d%03d",
DT[0],DT[1],DT[2],DT[3],DT[4],DT[5],DT[6],DT[7]);
printf(" %s\n",txt);
}
/*
* Computes the Greenwich mean time (GMT) at the next local
* civil time (LCT) occurrence of the specified hour and
* minute. If the time has already passed today, the GMT is
* computed for the target time tomorrow. Returns 0 if
* successful.
*/
int TargetGMT(uint16 hour, uint16 minute, int64 *target )
{
int16 err;
int16 DateTime[8];
int64 jts_current, jts_target;
/* Get GMT at time of call; convert to LCT */
jts_current = JULIANTIMESTAMP(GET_GMT);
jts_current = CONVERTTIMESTAMP(jts_current, GMT_TO_LCT,
MY_NODE, &err);
if (err) return err;
/*
* Convert the LCT time to a Gregorian date and time. Then
* adjust the fields of the Gregorian timestamp to get the
* desired target time.
*/
INTERPRETTIMESTAMP(jts_current, DateTime);
DateTime[3] = hour;
DateTime[4] = minute;
DateTime[5] = DateTime[6] = DateTime[7] = 0;
\*
* Convert the target time from Gregorian to Julian LCT.
* If target time is before current time-of-day, add a
* day's worth of microseconds to make the timer pop at the
* target time tomorrow.
*\
jts_target = COMPUTETIMESTAMP(DateTime, &err);
if (err) return -1; /* bad hour or minute */
if (jts_target < jts_current)
jts_target += 24*3600*1000000LL;