home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / rettig.zip / TRSOURCE.EXE / TIMESTR.C < prev    next >
C/C++ Source or Header  |  1990-10-22  |  1KB  |  55 lines

  1. /*********
  2. *  TIMESTR.C
  3. *
  4. *  by Tom Rettig
  5. *
  6. * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  7. *
  8. *  Syntax: TIMESTR( <expN> )
  9. *  Return: <expC> time string as "HH:MM:SS" from <expN> seconds.
  10. *          Empty time string "00:00:00" if <expN> is <= zero.
  11. *********/
  12.  
  13. #include "trlib.h"
  14.  
  15. TRTYPE timestr()
  16. {
  17.    static char ret[9];
  18.    static char funcname[] = { "timestr" };
  19.    long insecs;
  20.    int i, hours, mins, secs;
  21.  
  22.    if ( PCOUNT == 1 && ISNUM(1) )
  23.    {
  24.       insecs = _parnl(1);
  25.  
  26.       /* calculate time values and build time string */
  27.       if ( insecs <= 0 )
  28.       {
  29.          /* empty value */
  30.          for ( i = 0; i < 8; i++ )
  31.             ret[i] = ( i==TDELIM_1 || i==TDELIM_2 ) ? TIMEDELIM : ZEROC;
  32.       }
  33.       else
  34.       {
  35.          hours = (int)((insecs/3600)%24);
  36.          mins  = (int)((insecs/  60)%60);
  37.          secs  = (int)((insecs     )%60);
  38.  
  39.          ret[HOURS]    = DIGIT( hours/10 );
  40.          ret[HOUR ]    = DIGIT( hours%10 );
  41.          ret[TDELIM_1] = TIMEDELIM;
  42.          ret[MINS]     = DIGIT( mins/10 );
  43.          ret[MIN ]     = DIGIT( mins%10 );
  44.          ret[TDELIM_2] = TIMEDELIM;
  45.          ret[SECS]     = DIGIT( secs/10 );
  46.          ret[SEC ]     = DIGIT( secs%10 );
  47.       }
  48.       ret[TIMELEN] = NULLC;
  49.  
  50.       _retc( ret );
  51.    }
  52.    else
  53.       _retc( _tr_errmsgs(funcname,E_SYNTAX) );
  54. }
  55.