manipulating time strings

Post Reply
User avatar
Eoeo
Posts: 222
Joined: Mon Jun 04, 2012 12:00 pm

manipulating time strings

Post by Eoeo »

Where I can found functions for manipulating time strings?

I have for sample :

Code: Select all

cHoraE1    cHoraU1    cHoraE2   cHoraU2   cHoraE3   cHoraU3
08:00         14:00      15:00       16:47        17:10       19:30
 
and I must calculate the total of Hours and minutes,

if an employee has to do only 6 hours each day and his turn of Work is from "08:00" to "14:00"

the procedure must calculate also the flexibility negative and positive ( format 00:00 hours/minutes)


sample
FLNEG 05:10
FLPOS 01:10
User avatar
MarcoBoschi
Posts: 925
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy
Contact:

Re: manipulating time strings

Post by MarcoBoschi »

Eoeo,
do not use _ but centesimal when calculate elapsed time

Code: Select all

#include "fivewin.ch"
FUNCTION MAIN()
LOCAL cT1 , cT2

cT1 := "08:00"
cT2 := "14:00"

? cal_ore( cT1 , cT2 )

cT1 := "08:00"
cT2 := "14:06"

? cal_ore( cT1 , cT2 )

RETURN NIL

FUNCTION CAL_ORE( cT1, cT2 )


LOCAL nT1    := VAL( SUBSTR( cT1 , 1 , 2 ) ) + VAL( SUBSTR( cT1 , 4 , 2 ) ) / 60
LOCAL nT2    := VAL( SUBSTR( cT2 , 1 , 2 ) ) + VAL( SUBSTR( cT2 , 4 , 2 ) ) / 60
? nT1 , nT2
RETURN nT2 - nT1
 
Last result 6.10 is 1 hour and 10 cents of hours
10 cents of an hour are 6 minutes 10/100*60 minutes
Marco Boschi
info@marcoboschi.it
User avatar
Eoeo
Posts: 222
Joined: Mon Jun 04, 2012 12:00 pm

Re: manipulating time strings

Post by Eoeo »

Marco,


Image



I found other function in time.prg of clipper :

#include "FiveWin.ch"

Function test()

nEntrata1:="07:57"
nUscita1:="14:25"
nEntrata2:="15:57"
nUscita2:="16:41"
nEntrata3:="17:10"
nUscita3:="19:43"

Totale1:=TDIFF(nEntrata1, nUscita1)
Totale2:=TDIFF(nEntrata2, nUscita2)
Totale3:=TDIFF(nEntrata3, nUscita3)
Totale_Sec:=TTOS( Totale1 )+TTOS( Totale2 )+TTOS( Totale3 )
Totale:=STOT( Totale_Sec)
TotaleWork:= "06:00"
Tot_gen:= Totale_Sec-TTOS(TotaleWork)


MsgInfo("Mattina :"+totale1+" +"+CRLF+;
"Pomeriggio :"+totale2+" +"+CRLF+;
"Sera :"+totale3+" +"+CRLF+;
"Totale ore :"+Totale+" -"+CRLF+;
"Ore Lavoro :"+TotaleWork+CRLF+;
"Totale ore :"+STOT( Tot_gen))


retu NIL



Now My problem is to calculate the flexibility negative and positive

sample :

Entrata1:="07:57"
Uscita1 :="13:58"
Total = 05:58 ( I calc from 08:00 to 14:00)
the employe made not six Hours of Work and it is a FLNEG of 2 minutes


Entrata1:="07:57"
Uscita1 :="14:25"
Total = 06:25 ( I calc from 08:00 to 14:00)
the employe made over six Hours of Work and it is a FLPOS of 25 minutes

How i can make to calculate FLNEG and FLPOS with a function ?
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: manipulating time strings

Post by ukoenig »

Silvio,

this function calculates everything from given Start Day / time to End Day / time :

Only a Time-calculation :

Image

Sample :

tStart := '12:45:12'
tEnd := '10:20:30'
dStart := Date()
dEnd := Date()
( we add a Day, because time-end < time-start )
IF VAl( SUBSTR( tEnd, 1, 2 ) ) < VAl( SUBSTR( tStart, 1, 2 ) )
dEnd++
ENDIF
aDiff := ELAPSED( dStart, dEnd, tStart, tEnd )

The Function returns :
--------------------------
aDiff[1,1] -> Days
aDiff[2,1] -> Hours
aDiff[3,1] -> Minutes
aDiff[[4,1] -> Seconds


MsgAlert( "Hours : " + STR(aDiff[2,1]) + CRLF + ;
"Minutes : " + STR(aDiff[3,1]) + CRLF + ;
"Seconds : " + STR(aDiff[4,1]) , "12:45:12 to 10:20:30 " )

Code: Select all

FUNCTION 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', )
IF( VALTYPE(cTimeEnd)   != 'C', cTimeEnd   := '00:00:00', )
 
nTotalSec  := (dEnd - dStart) * 86400                              + ;
                VAL(cTimeEnd)   *  3600                              + ;
                VAL(SUBSTR(cTimeEnd,AT(':', cTimeEnd)+1,2)) * 60     + ;
                IF(RAT(':', cTimeEnd) == AT(':', cTimeEnd), 0,         ;
                VAL(SUBSTR(cTimeEnd,RAT(':', cTimeEnd)+1)))          - ;
                VAL(cTimeStart) * 3600                               - ;
                VAL(SUBSTR(cTimeStart,AT(':', cTimeStart)+1,2)) * 60 - ;
                IF(RAT(':', cTimeStart) == AT(':', cTimeStart), 0,     ;
                VAL(SUBSTR(cTimeStart,RAT(':', cTimeStart)+1)))
 
nTemp := nTotalSec
 
FOR nCtr = 1 to 4
    nConstant := IF(nCtr == 1, 86400, IF(nCtr == 2, 3600, IF( nCtr == 3, 60, 1)))
    aRetVal[nCtr,1] := INT(nTemp/nConstant)
    aRetval[nCtr,2] := nTotalSec / nConstant
    nTemp -= aRetVal[nCtr,1] * nConstant
NEXT
 
RETURN aRetVal
 
Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
Eoeo
Posts: 222
Joined: Mon Jun 04, 2012 12:00 pm

Re: manipulating time strings

Post by Eoeo »

Thanks Uwe,

for calculation I resolved

Now I must resolve the second Problem :

I must calculate the the flexibility negative and positive

See these samples pls

sample :

Entrata1:="07:57"
Uscita1 :="13:58"
Total = 05:58 ( I calc from 08:00 to 14:00)
the employe made not six Hours of Work and it is a FLNEG of 2 minutes


Entrata1:="07:57"
Uscita1 :="14:25"
Total = 06:25 ( I calc from 08:00 to 14:00)
the employe made over six Hours of Work and it is a FLPOS of 25 minutes

How i can make to calculate FLNEG and FLPOS with a function ?
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: manipulating time strings

Post by ukoenig »

Silvio,

I don*t understand. Do You want to calc ( round ) to a full hour ( at start ) ???

Entrata1:="07:57"
( I calc from 08:00 )

Best Regards
Uwe :?:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
Eoeo
Posts: 222
Joined: Mon Jun 04, 2012 12:00 pm

Re: manipulating time strings

Post by Eoeo »

No please :

I must calculate the the flexibility negative and positive

I have TO MAKE 6 HOURS

TIME OF INIT WORK :="07:57"

TIME OF END WORK :="13:58"

Total OF HOURS WORKED = 05:58 ( I calc from 08:00 to 14:00)

WITH THIS SAMPLE i HAVE A NEGATIVE flexibility BECAUSE the worker MADE ONLY 5.58 AND NOT 6 HOURS


I explain

Total OF HOURS WORKED = 05:58 ( I calc from 08:00 to 14:00)

the worker can acces at work at 07:57 but his time work is from 08:00 to 14:00 and I calc from 08:00 to the end of work and this case 13:58
in this case there is negative flexibility of 2 minutes because the worker must made 6 hours and he made only 5:58
User avatar
Eoeo
Posts: 222
Joined: Mon Jun 04, 2012 12:00 pm

Re: manipulating time strings

Post by Eoeo »

If we see the sample test :

Worker : Jonh
Morning
nEntrata1:="07:57"
nUscita1:="14:25"

here the worker made 6 Hours of Work with 25 minutes of positive flexibility
Afternoon
nEntrata2:="15:57"
nUscita2:="16:57"

here the worker is on positive flexibility and he made 1 hours of positive flexibility
Evening
nEntrata3:="17:00"
nUscita3:="19:00"

here the worker is also on positive flexibility and he made 2 hours of positive flexibility


the worker made total 3 hours and 25 minutes of positive flexibility
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: manipulating time strings

Post by ukoenig »

Silvio,

I think that can be used as a basic with carrying on more calculations :

Image

Result, with the extra lines :

Image

// the worker made 6 Hours of Work with 25 minutes of positive flexibility
MsgAlert( ELTIME( "07:57:00", "14:25:00" ), "07:57 <> 14:25" )
// the worker is on positive flexibility and he made 1 hours of positive flexibility
MsgAlert( ELTIME( "15:57:00", "16:57:00" ), "15:57 <> 16:57" )
// the worker is on positive flexibility and he made 2 hours of positive flexibility
MsgAlert( ELTIME( "17:00:00", "19:00:00" ), "17:00 <> 19:00" )

// the worker made total 3 hours and 25 minutes of positive flexibility

Code: Select all

FUNCTION ELTIME(cTIME1,cTIME2)
local  nTIME1, nTIME2, nDELSECS, nHRS, nMINS, nSECS, nSECS1, nSECS2

// add this, to ignore a time < 08:00 ( set to 08:00 )
// IF val(substr(cTIME1,1,2)) < 8 // 08:00
//  cTIME1 := "08:00:00"
// ENDIF

nSECS1 := (val(substr(cTIME1,1,2)) * 3600) +;
              (val(substr(cTIME1,4,2)) * 60) + (val(substr(cTIME1,7)))
nSECS2 := (val(substr(cTIME2,1,2)) * 3600) +;
              (val(substr(cTIME2,4,2)) * 60) + (val(substr(cTIME2,7)))
nDELSECS := abs(nSECS2 - nSECS1)
nHRS := int(nDELSECS / 3600)
nMINS := int((nDELSECS - nHRS * 3600) / 60)
nSECS := nDELSECS - (nHRS * 3600) - (nMINS * 60)

// add this, to ignore the hours < 14:00 ( 08:00 - 14:00 = 6 )
// IF val(substr(cTIME2,1,2)) >= 14 // 14:00
//  nHRS := nHRS - 6 ( counts only houres > 14:00
// ENDIF

RETURN right("00" + ltrim(str(nHRS)),2) + ;
     ":" + right("00" + ltrim(str(nMINS)),2) + ;
     ":" + right("00" + ltrim(str(nSECS)),2)
 
Best Regards
Uwe :?:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
Eoeo
Posts: 222
Joined: Mon Jun 04, 2012 12:00 pm

Re: manipulating time strings

Post by Eoeo »

this afternoon I try it . thanks
Post Reply