/*Module/File Name: EDCDT3 */
/********************************************************************/
/* */
/*Function : CEESECS - convert timestamp to seconds */
/* : CEESECI - convert seconds to time components */
/* : CEEISEC - convert time components to seconds */
/* : CEEDATM - convert seconds to timeStamp */
/* : */
/*32 months is added to the timestamp 11/02/92 05:22 giving */
/*the new timestamp 07/02/95 05:22. */
/* */
/*CEESECS is used to convert timestamp 11/02/92 05:22 to seconds. */
/*CEESECI is used to convert the seconds to date/time components. */
/*32 months is added to the month component. */
/*CEEISEC is then used to convert date/time components to seconds. */
/*CEEDATM is then used to build a new timestamp for the */
/*new time. */
/* */
/********************************************************************/
#include <stdio.h>
#include <string.h>
#include <leawi.h>
#include <ceeedcct.h>
#define TimeStamp "11/02/92 05:22"
#define displacement 32
void main ()
{
_VSTRING Time_Stamp;
_CHAR80 New_TimeStamp;
_VSTRING picstr;
_FLOAT8 Lilian_Seconds;
_FLOAT8 New_Secs;
_FEEDBACK FC;
char New_Time[15];
int Month_in_Century;
/*******************************************
Date/time components for CEESECI, CEEISEC.
*******************************************/
_INT4 year;
_INT4 month;
_INT4 days;
_INT4 hours;
_INT4 minutes;
_INT4 seconds;
_INT4 millsec;
/***************************************************************
The date picstr must be set to match the timestamp format.
***************************************************************/
strcpy (picstr.string,"MM/DD/YY HH:MI");
picstr.length = 14;
strncpy(Time_Stamp.string,TimeStamp,14);
Time_Stamp.length = 14;
/*********************************************************
CEESECS takes the timestamp "11/02/92 05:22" and returns
a double-precision Lilian seconds tally in Lilian_Seconds
*********************************************************/
CEESECS ( &Time_Stamp, &picstr , &Lilian_Seconds , &FC );
if ((_FBCHECK (FC, CEE000)) == 0)
{
/***************************************************************
CEESECI converts the Lilian seconds tally in Lilian_Seconds and
returns date/time components.
***************************************************************/
CEESECI ( &Lilian_Seconds, &year, &month, &days, &hours,
&minutes, &seconds, &millsec, &FC);
if ((_FBCHECK (FC, CEE000)) == 0)
{
/***************************************************************
The month component of the timestamp is converted to
month-in-century.
Then a new month and a new year are computed from the
new month-in-century number. The month date/time component has a
range between 1 and 12.
***************************************************************/
Month_in_Century = year*12 + month + displacement - 1;
year = Month_in_Century / 12;
month = (Month_in_Century % 12) + 1;
/* *************************************************************
The month date/time component has been shifted
forward 32 months. Our examples gets a new Lilian seconds
tally based on the new month and year components.
This is done with a call to function CEEISEC.
The new Lilian seconds tally is placed in the double-precision
variable Lilian_Seconds.
***************************************************************/
CEEISEC (&year,
&month,
&days,
&hours,
&minutes,
&seconds,
&millsec, &Lilian_Seconds, &FC );
if ((_FBCHECK (FC, CEE000)) == 0)
{
/*************************************************************
CEEDATM is invoked to get a new timestamp value based on the
new Lilian seconds tally in Lilian_Seconds.
*************************************************************/
CEEDATM ( &Lilian_Seconds,
&picstr ,
New_TimeStamp ,
&FC );
if ((_FBCHECK (FC, CEE000)) == 0)
{
New_TimeStamp[14] = '\0';
sprintf(New_Time,"%s\0",New_TimeStamp);
if ( displacement < 0 )
printf("%s is the time %d months before %s.\n",
New_Time, displacement, TimeStamp);
else
printf("%s will be the time %d months after %s.\n",
New_Time, displacement, TimeStamp);
}
else
printf ( "Error converting Seconds to TimeStamp.\n" );
}
else
printf ( "Error converting Components to seconds.\n" );
}
else
printf ( "Error converting seconds to components.\n" );
}
else
printf ( "Error converting TimeStamp to seconds\n" );
}