home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / nfsrc21.zip / ELTIME.PRG < prev    next >
Text File  |  1991-08-16  |  2KB  |  72 lines

  1. /*
  2.  * File......: ELTIME.PRG
  3.  * Author....: Alexander B. Spencer
  4.  * CIS ID....: 76276,1012
  5.  * Date......: $Date:   15 Aug 1991 23:06:14  $
  6.  * Revision..: $Revision:   1.2  $
  7.  * Log file..: $Logfile:   E:/nanfor/src/eltime.prv  $
  8.  * 
  9.  * This is an original work by Alexander B. Spencer and is placed in the
  10.  * public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log:   E:/nanfor/src/eltime.prv  $
  16.  * 
  17.  *    Rev 1.2   15 Aug 1991 23:06:14   GLENN
  18.  * Forest Belt proofread/edited/cleaned up doc
  19.  * 
  20.  *    Rev 1.1   14 Jun 1991 20:58:56   GLENN
  21.  * Two locals, nSECS1 and nSECS2, were not declared; this was fixed.
  22.  * 
  23.  *    Rev 1.0   07 Jun 1991 23:39:46   GLENN
  24.  * Initial revision.
  25.  *
  26.  */
  27.  
  28.  
  29. /*  $DOC$
  30.  *  $FUNCNAME$
  31.  *     FT_ELTIME()
  32.  *  $CATEGORY$
  33.  *     Date/Time
  34.  *  $ONELINER$
  35.  *     Compute difference between times in hours, minutes, seconds.
  36.  *  $SYNTAX$
  37.  *     FT_ELTIME( <cTime1>, <cTime2> ) -> cDiff
  38.  *  $ARGUMENTS$
  39.  *     <cTime1, cTime2>  character strings representing times in
  40.  *        hh:mm:ss format.
  41.  *  $RETURNS$
  42.  *     <cDiff>  character string representing time difference in
  43.  *        hh:mm:ss format.
  44.  *  $DESCRIPTION$
  45.  *     Return the absolute difference between two times in hh:mm:ss format
  46.  *     in character hours, minutes and seconds (hh:mm:ss).
  47.  *  $EXAMPLES$
  48.  *     FT_ELTIME( "22:40:12", "23:55:17" ) -> 01:15:05
  49.  *     FT_ELTIME( "23:55:17", "22:40:12" ) -> 01:15:05
  50.  *  $SEEALSO$
  51.  *     FT_ELAPMIN() FT_MIL2MIN() FT_MIN2MIL()
  52.  *  $END$
  53.  */
  54.  
  55. function FT_ELTIME(cTIME1,cTIME2)
  56.   local  nTIME1, nTIME2, nDELSECS, nHRS, nMINS, nSECS, nSECS1, nSECS2
  57.  
  58.   nSECS1   := (val(substr(cTIME1,1,2)) * 3600) +;
  59.               (val(substr(cTIME1,4,2)) * 60) + (val(substr(cTIME1,7)))
  60.   nSECS2   := (val(substr(cTIME2,1,2)) * 3600) +;
  61.               (val(substr(cTIME2,4,2)) * 60) + (val(substr(cTIME2,7)))
  62.   nDELSECS := abs(nSECS2 - nSECS1)
  63.   nHRS     := int(nDELSECS / 3600)
  64.   nMINS    := int((nDELSECS - nHRS * 3600) / 60)
  65.   nSECS    := nDELSECS - (nHRS * 3600) - (nMINS * 60)
  66.  
  67.   return right("00" + ltrim(str(nHRS)),2) + ;
  68.      ":" + ;
  69.      right("00" + ltrim(str(nMINS)),2) + ;
  70.      ":" + ;
  71.      right("00" + ltrim(str(nSECS)),2)
  72.