home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
xbase
/
library
/
clipper
/
rettig
/
source
/
maketime.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-21
|
2KB
|
70 lines
/*********
* MAKETIME.C
*
* by Tom Rettig
*
* Placed in the public domain by Tom Rettig Associates, 10/22/1990.
*
* Syntax: MAKETIME( <time string> )
* Return: <expC> valid time string from invalid <time string>.
*********/
#include "trlib.h"
TRTYPE maketime()
{
static char ret[9];
static char funcname[] = { "maketime" };
char *intime;
long insecs;
int i, hours, mins, secs;
if ( PCOUNT == 1 && ISCHAR(1) )
{
intime = _parc(1);
/* trap for time string format */
if ( ISTS(intime) )
{
/* convert to seconds */
insecs = (long) ( (ADTOI(intime[HOURS])*36000) +
(ADTOI(intime[HOUR ])* 3600) +
(ADTOI(intime[MINS ])* 600) +
(ADTOI(intime[MIN ])* 60) +
(ADTOI(intime[SECS ])* 10) +
ADTOI(intime[SEC ]) );
/* calculate time values and build time string */
if ( insecs <= 0 )
{
/* empty value */
for ( i = 0; i < 8; i++ )
ret[i] = ( i==TDELIM_1 || i==TDELIM_2 ) ? TIMEDELIM : ZEROC;
}
else
{
hours = (int)((insecs/3600)%24);
mins = (int)((insecs/ 60)%60);
secs = (int)((insecs )%60);
ret[HOURS] = DIGIT( hours/10 );
ret[HOUR ] = DIGIT( hours%10 );
ret[TDELIM_1] = TIMEDELIM;
ret[MINS] = DIGIT( mins/10 );
ret[MIN ] = DIGIT( mins%10 );
ret[TDELIM_2] = TIMEDELIM;
ret[SECS] = DIGIT( secs/10 );
ret[SEC ] = DIGIT( secs%10 );
}
ret[TIMELEN] = NULLC;
_retc( ret );
}
else
_retc( _tr_errmsgs(funcname,E_SYNTAX) );
}
else
_retc( _tr_errmsgs(funcname,E_SYNTAX) );
}