* tests/longdev.prg
* tests/hbpptest/hbpptest.prg
* tests/testcgi.prg
* tests/foreach.prg
* tests/onidle.prg
* tests/tstchbx.prg
* tests/codebl.prg
* tests/tstdbi.prg
* tests/vmasort.prg
* tests/tstasort.prg
* tests/testbrw.prg
* tests/inkeytst.prg
* tests/testrdd2.prg
* tests/keywords.prg
* tests/testhtml.prg
* tests/readhrb.prg
* tests/stripem.prg
* tests/wvtext.prg
* tests/testpre.prg
* tests/seconds.prg
* tests/fsplit.prg
* tests/mousetst.prg
* contrib/hbmysql/tmysql.prg
* contrib/hbct/numconv.prg
* contrib/hbct/ctmisc.prg
* contrib/hbodbc/todbc.prg
* contrib/hbapollo/tests/apollo.prg
* contrib/hbnf/acctyear.prg
* contrib/hbnf/acctadj.prg
* contrib/hbnf/nwsem.prg
* contrib/hbnf/week.prg
* contrib/hbnf/acctmnth.prg
* contrib/hbnf/savearr.prg
* contrib/hbnf/madd.prg
* contrib/hbnf/mouse1.prg
* contrib/hbnf/month.prg
* contrib/hbnf/findith.prg
* contrib/hbnf/acctweek.prg
* contrib/hbnf/pegs.prg
* contrib/hbnf/acctqtr.prg
* contrib/hbnf/nooccur.prg
* contrib/hbnf/dayofyr.prg
* contrib/hbnf/menu1.prg
* contrib/hbnf/sqzn.prg
* contrib/hbnf/asum.prg
* contrib/hbnf/aavg.prg
* contrib/hbnf/any2any.prg
* contrib/hbnf/adessort.prg
* contrib/hbnf/amedian.prg
* contrib/hbnf/blink.prg
* contrib/hbnf/qtr.prg
* contrib/hbnf/aredit.prg
* contrib/hbnf/xbox.prg
* contrib/hbnf/ftround.prg
* contrib/hbnf/invclr.prg
* contrib/hbnf/tempfile.prg
* contrib/hbnf/diskfunc.prg
* contrib/hbnf/mouse2.prg
* contrib/hbnf/daytobow.prg
* contrib/hbnf/anomatch.prg
* contrib/hbnf/datecnfg.prg
* contrib/hbnf/tbwhile.prg
* contrib/hbnf/year.prg
* contrib/hbnf/elapsed.prg
* contrib/hbnf/dfile.prg
* contrib/hbnf/clrsel.prg
* contrib/hbmisc/twirler.prg
* contrib/hbmisc/fileread.prg
* contrib/hbmisc/stringp.prg
* contrib/hbgf/hbgfw32/winctrl.prg
* contrib/hbgf/hbgfw32/form.prg
* contrib/hbgf/hbgfos2/winctrl.prg
* contrib/hbgf/hbgfos2/tform.prg
* contrib/hbtip/httpcln.prg
* contrib/hbvpdf/hbvpdf.prg
* contrib/hbvpdf/hbvpdft.prg
* contrib/examples/guestbk/guestbk.prg
* contrib/examples/pe/editorhi.prg
* Some more general code cleanups ( if() -> iif() ).
132 lines
4.1 KiB
Plaintext
132 lines
4.1 KiB
Plaintext
/*
|
|
* $Id$
|
|
*/
|
|
|
|
/*
|
|
* File......: elapsed.prg
|
|
* Author....: Jo W. French dba Practical Computing
|
|
* CIS ID....: ?
|
|
*
|
|
* The functions contained herein are the original work of Jo W. French
|
|
* and are placed in the public domain.
|
|
*
|
|
* Modification history:
|
|
* ---------------------
|
|
*
|
|
* Rev 1.3 28 Sep 1992 00:37:56 GLENN
|
|
* Jo French cleaned up.
|
|
*
|
|
* Rev 1.2 15 Aug 1991 23:05:44 GLENN
|
|
* Forest Belt proofread/edited/cleaned up doc
|
|
*
|
|
* Rev 1.1 14 Jun 1991 19:51:46 GLENN
|
|
* Minor edit to file header
|
|
*
|
|
* Rev 1.0 01 Apr 1991 01:01:18 GLENN
|
|
* Nanforum Toolkit
|
|
*
|
|
*/
|
|
|
|
|
|
#ifdef FT_TEST
|
|
|
|
FUNCTION DEMO()
|
|
LOCAL dStart, dEnd, cTimeStart, cTimeEnd, n, aDataTest := {}
|
|
dStart := CTOD('11/28/90')
|
|
dEnd := CTOD('11/30/90')
|
|
cTimeStart := "08:00:00"
|
|
cTimeEnd := "12:10:30"
|
|
|
|
aDataTest := FT_ELAPSED(dStart,dEnd,cTimeStart,cTimeEnd)
|
|
FOR n = 1 to 4
|
|
? aDataTest[n,1], STR(aDataTest[n,2], 12, 4)
|
|
?? " "
|
|
?? iif(n == 1, 'Days', iif( n== 2, 'Hours', iif( n == 3, 'Mins.', 'Secs.')))
|
|
NEXT
|
|
RETURN NIL
|
|
|
|
#endif
|
|
|
|
/* $DOC$
|
|
* $FUNCNAME$
|
|
* FT_ELAPSED()
|
|
* $CATEGORY$
|
|
* Date/Time
|
|
* $ONELINER$
|
|
* Return elapsed time between two days and/or times
|
|
* $SYNTAX$
|
|
* FT_ELAPSED([ <dStart> ], [ <dEnd> ], ;
|
|
* <cTimeStart>, <cTimeEnd>) -> aTimedata
|
|
* $ARGUMENTS$
|
|
* <dStart> is any valid date in any date format. Defaults to DATE().
|
|
*
|
|
* <dEnd> is any valid date in any date format. Defaults to DATE().
|
|
*
|
|
* <cTimeStart> is a valid Time string of the format 'hh:mm:ss' where
|
|
* hh is hours in 24-hour format.
|
|
*
|
|
* <cTimeEnd> is a valid Time string of the format 'hh:mm:ss' where
|
|
* hh is hours in 24-hour format.
|
|
* $RETURNS$
|
|
* A two-dimensional array containing elapsed time data.
|
|
* $DESCRIPTION$
|
|
* FT_ELAPSED() calculates the elapsed time between two Date/Time events.
|
|
*
|
|
* It returns an array which contains the following data:
|
|
*
|
|
* aRetVal[1,1] Integer Days aRetVal[1,2] Total Days (nn.nnnn)
|
|
* aRetVal[2,1] Integer Hours aRetVal[2,2] Total Hours (nn.nnnn)
|
|
* aRetVal[3,1] Integer Minutes aRetVal[3,2] Total Minutes (nn.nnnn)
|
|
* aRetVal[4,1] Integer Seconds aRetVal[4,2] Total Seconds (nn)
|
|
* $EXAMPLES$
|
|
* FT_ELAPSED(CTOD('11/28/90'), CTOD('11/30/90'), '08:00:00', '12:10:30')
|
|
* will return:
|
|
*
|
|
* aRetVal[1,1] -> 2 (Days) aRetVal[1,2] -> 2.1740 Days
|
|
* aRetVal[2,1] -> 4 (Hours) aRetVal[2,2] -> 52.1750 Hours
|
|
* aRetVal[3,1] -> 10 (Minutes) aRetVal[3,2] -> 3130.5000 Minutes
|
|
* aRetVal[4,1] -> 30 (Seconds) aRetVal[4,2] -> 187830 Seconds
|
|
* $END$
|
|
*/
|
|
|
|
FUNCTION FT_ELAPSED(dStart, dEnd, cTimeStart, cTimeEnd)
|
|
LOCAL nTotalSec, nCtr, nConstant, nTemp, aRetVal[4,2]
|
|
|
|
IF ! ( VALTYPE(dStart) $ 'DC' )
|
|
dStart := DATE()
|
|
ELSEIF VALTYPE(dStart) == 'C'
|
|
cTimeStart := dStart
|
|
dStart := DATE()
|
|
ENDIF
|
|
|
|
IF ! ( VALTYPE(dEnd) $ 'DC' )
|
|
dEnd := DATE()
|
|
ELSEIF VALTYPE(dEnd) == 'C'
|
|
cTimeEnd := dEnd
|
|
dEnd := DATE()
|
|
ENDIF
|
|
|
|
IF VALTYPE(cTimeStart) != 'C' ; cTimeStart := '00:00:00' ; ENDIF
|
|
IF VALTYPE(cTimeEnd) != 'C' ; cTimeEnd := '00:00:00' ; ENDIF
|
|
|
|
nTotalSec := (dEnd - dStart) * 86400 + ;
|
|
VAL(cTimeEnd) * 3600 + ;
|
|
VAL(SUBSTR(cTimeEnd,AT(':', cTimeEnd)+1,2)) * 60 + ;
|
|
iif(RAT(':', cTimeEnd) == AT(':', cTimeEnd), 0, ;
|
|
VAL(SUBSTR(cTimeEnd,RAT(':', cTimeEnd)+1))) - ;
|
|
VAL(cTimeStart) * 3600 - ;
|
|
VAL(SUBSTR(cTimeStart,AT(':', cTimeStart)+1,2)) * 60 - ;
|
|
iif(RAT(':', cTimeStart) == AT(':', cTimeStart), 0, ;
|
|
VAL(SUBSTR(cTimeStart,RAT(':', cTimeStart)+1)))
|
|
|
|
nTemp := nTotalSec
|
|
|
|
FOR nCtr = 1 to 4
|
|
nConstant := iif(nCtr == 1, 86400, iif(nCtr == 2, 3600, iif( nCtr == 3, 60, 1)))
|
|
aRetVal[nCtr,1] := INT(nTemp/nConstant)
|
|
aRetval[nCtr,2] := nTotalSec / nConstant
|
|
nTemp -= aRetVal[nCtr,1] * nConstant
|
|
NEXT
|
|
|
|
RETURN aRetVal
|