I want compare/test differencies of elapsed time.
But when I run next code, it returns wrong values.
Please, can you look, where is problem?
Many thanks.
Regards,
Zdeno
Code: Select all
***********************
Function MyTestElapTime()
***********************
Local cDate := Date()
Local cTime := Time()
Local aDT := { { CToD( '21.03.2016' ), '08:58:00' }, ;
{ CToD( '21.03.2016' ), '08:59:00' }, ;
{ CToD( '21.03.2016' ), '09:00:00' }, ;
{ CToD( '21.03.2016' ), '09:01:00' }, ;
{ CToD( '21.03.2016' ), '09:02:00' }, ;
;
{ CToD( '21.03.2016' ), '16:58:00' }, ;
{ CToD( '21.03.2016' ), '16:59:00' }, ;
{ CToD( '21.03.2016' ), '16:00:00' }, ;
{ CToD( '21.03.2016' ), '16:01:00' }, ;
{ CToD( '21.03.2016' ), '16:02:00' }, ;
;
{ CToD( '21.03.2016' ), '23:58:00' }, ;
{ CToD( '21.03.2016' ), '23:59:00' }, ;
;
{ CToD( '22.03.2016' ), '00:00:00' }, ;
{ CToD( '22.03.2016' ), '00:01:00' }, ;
{ CToD( '22.03.2016' ), '00:02:00' } ;
}
Local i, naDT := Len( aDT )
Local nDiff
Local cText := ''
cText += ( DToC( cDate ) + ' ' + cTime + CRLF )
cText += CRLF
For i := 1 To naDT
nDiff := ElapTime( cDate, cTime, aDT[i,1], aDT[i,2] )
cText += ( DToC( aDT[i,1] ) + ' ' + aDT[i,2] + ' - ' + Str( nDiff, 12, 2 ) + CRLF )
* wtf aDT[i], nDiff, '*'
Next
wtf cText
* wtf '***'
Return ( NIL )
*
*****************
FUNCTION ElapTime( dDate, cTime, dDateStart, cTimeStart )
*****************
LOCAL nSeconds, nSecondsStart, nDiff
nSeconds := Val(Dtos(dDate)) * 60 * 60 * 24 + TimeToSec(cTime)
nSecondsStart := Val(Dtos(dDateStart)) * 60 * 60 * 24 + TimeToSec(cTimeStart)
nDiff := nSeconds - nSecondsStart
* wtf nSeconds, nSecondsStart, nDiff
RETURN ( nSeconds - nSecondsStart )
* ----------
******************
FUNCTION TimeToSec( cTime )
******************
LOCAL nHours, nMinutes, nSeconds
If Empty( cTime )
cTime := Time()
EndIf
nHours := Val(Substr(cTime,1,2))
nMinutes := Val(Substr(cTime,4,2))
nSeconds := Val(Substr(cTime,7,2))
RETURN ( (nHours * 60 * 24) + (nMinutes * 60) + nSeconds )
*