home *** CD-ROM | disk | FTP | other *** search
- /*********
- * TIMESTR.C
- *
- * by Tom Rettig
- *
- * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
- *
- * Syntax: TIMESTR( <expN> )
- * Return: <expC> time string as "HH:MM:SS" from <expN> seconds.
- * Empty time string "00:00:00" if <expN> is <= zero.
- *********/
-
- #include "trlib.h"
-
- TRTYPE timestr()
- {
- static char ret[9];
- static char funcname[] = { "timestr" };
- long insecs;
- int i, hours, mins, secs;
-
- if ( PCOUNT == 1 && ISNUM(1) )
- {
- insecs = _parnl(1);
-
- /* 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) );
- }
-