kapiaba Posted June 13, 2013 Report Share Posted June 13, 2013 blz galera, alguém tem algo parecido com isto em fivewin? ******************************************************************* *| Autor...: Anderson Vieira *| Objetivo: Sistema para obter a contagem de tempo entre dois periodos *| Compilar: Clipper teste19.prg *| Linkar..: *| Criaco..: 06/07/2012 12:27 ******************************************************************* #Include "FiveWin.ch" FUNCTION HORATOSEC() set date to brit set cent on cls //--DESCOMENTE ABAIXO PARA TESTAR AS FUNCOES SUBSTITUTAS DA TIMETOSEC() //--E SECTOTIME() DA CT a=" 46:10:25" b=" 49:10:25" do while .t. @01,00 say "Teste das funcoes hh2ss() e ss2hh() substituindo a funcao timetosec() e " @02,00 say "sectotime() da CATOOLS ja que estas permite uma hora de 0 a 23h " @04,00 say "a) Hora inicial do calculo" get a pict"99999:99:99" @05,00 say "b) Hora final do calculo" get b pict"99999:99:99" read if lastkey()=27 return elseif lastkey()=3 exit endif cls @07,00 say "Resultado da hh2ss()..: " @07,col() say alltrim(str(hh2ss(a))) @07,col()+1 say "segundos" @08,00 say "Resultado da ss2hh()..: " @08,col() say ss2hh(hh2ss(a)) @09,00 say "Somando as horas (a+: "+ss2hh(hh2ss(a)+hh2ss() @10,00 say "Somando as horas (b-a): "+ss2hh(hh2ss(-hh2ss(a)) @24,00 say "Tecle [PageDown] para ir ao proximo teste [Esc] Sair" colo "gr+/n" enddo //-- FIM DO COMENTARIO //--DESCOMENTE ABAIXO PARA RETORNAR O CALCULO DE TEMPO DENTRO DE UM PERIODO, RETORNANDO //--ANO, MES, DIA, HORA, MINUTO E SEGUNDO RESTANTES. a="17:13:50" b="21:52:43" c=ctod("02/07/2012") d=ctod("03/07/2012") cls @01,00 say "Teste de calculo de tempo dentro de um periodo, retornando" @02,00 say "ANO, MES, DIA, HORA, MINUTO E SEGUNDO RESTANTES." @03,00 say "horaperiodo()" do while .t. @5,0 say "hora inicial:" get a pict"99:99:99" @6,0 say "hora final :" get b pict"99:99:99" @7,0 say "data inicial:" get c @8,0 say "data final..:" get d read if lastkey()=27 return endif *--Ret sera preenchido com um array com 5 elementos ret=horaperiodo(a,b,c,d) @11,00 say "Contagem de Tempo" @11,50 say "Tempo total HH:MM:SS" @13,00 say "Anos.: " + ret[2] @14,00 say "Meses: " + ret[3] @15,00 say "Dias.: " + ret[4] @16,00 say "Horas: " + ret[5] @13,50 say padl(ret[1],20) @24,00 say "Tecle [ESC] Terminar " colo "gr+/n" enddo //--FIM DO COMENTARIO RETURN NIL FUNCTION horaperiodo(cHorI,cHorF,dDatI,dDatF) *************************************************************************************** *| Empresa.: NSI Softwares e Sites *| Autor...: Anderson Vieira *| Objetivo: Obter a diferenca em hora entre um periodo *| *| *| Retorno.: Array com 5 elementos *| Conteudo: 1o elemento: total da contagem no formato HH:MM:SS *| 2o elemento: total de ano(s) *| 3o elemento: total de mes(s) *| 4o elemento: total de dia(s) *| 5o elemento: total de horas restantes *| *************************************************************************************** LOCAL nDias:=0,rHoras:=0, rPeriodo:=0 *--calcula diferenca de dias if dDatF>dDatI nDias=dDatF-dDatI endif *--se nDias for 0 faz a diferenca de horas if nDias=0 if cHorI="00:00:00" .and. cHorF="24:00:00" rHoras:="24:00:00" else rHoras:=Elaptime(cHorI,cHorF) endif else //if nDias=1 *--se for 1 dia indica de um dia para outro entao tem que extrair *--cHorI ate 24:00:00 e de 00:00:00 ate cHorF if cHorI="00:00:00".and.cHorF="24:00:00" *--equivale a um dia rPeriodo=86400 nDias+=1 else //rPeriodo=TIMETOSEC(Elaptime(cHorI,"24:00:00"))+TIMETOSEC(Elaptime("00:00:00",cHorF)) rPeriodo=HH2SS(Elaptime(cHorI,"24:00:00"))+HH2SS(Elaptime("00:00:00",cHorF)) endif if rPeriodo<86400.and.cHorF="24:00:00" rPeriodo+=86400 elseif rPeriodo=0.and.cHorI="00:00:00".and.cHorF="00:00:00" rPeriodo+=nDias*86400 elseif rPeriodo<86400 *@08,00 say rPeriodo colo "g+/n" *@09,00 say rPeriodo colo "gr+/n" if nDias>1 rPeriodo+=(nDias-1)*86400 if cHorI!="00:00:00" nDias-- endif else if cHorI="00:00:00".or.cHorI="24:00:00" rPeriodo+=86400 endif *rPeriodo+=86400 *@14,50 say rPeriodo colo "w+/r" *wait"veja" endif *@10,00 say rPeriodo *@10,50 say nDias *wait"" endif *--divide por 86400 para se obter os dias, o resto ‚ segundos *@21,00 say rPeriodo colo "r/n" if rPeriodo>=86400 //rHoras=alltrim(str(nDias*24+val(substr(SECTOTIME(rPeriodo%86400),1,2))))+":"+substr(SECTOTIME(rPeriodo%86400),4) rHoras=alltrim(str(nDias*24+val(substr(SS2HH(rPeriodo%86400),1,2))))+":"+substr(SS2HH(rPeriodo%86400),4) else if rPeriodo<0 //rHoras=alltrim(str(nDias*24-val(substr(SECTOTIME(-1*rPeriodo),1,2))))+":"+substr(SECTOTIME(-1*rPeriodo),4) rHoras=alltrim(str(nDias*24-val(substr(SS2HH(-1*rPeriodo),1,2))))+":"+substr(SS2HH(-1*rPeriodo),4) else //rHoras:=SECTOTIME(TIMETOSEC(Elaptime(cHorI,"24:00:00"))+TIMETOSEC(Elaptime("00:00:00",cHorF))) rHoras:=SS2HH(HH2SS(Elaptime(cHorI,"24:00:00"))+HH2SS(Elaptime("00:00:00",cHorF))) endif endif endif *--criacao dos itens de cada elemento do array nTotdias=int(val(substr(rHoras,1,at(":",rHoras)-1))) nDias=int(val(substr(rHoras,1,at(":",rHoras)-1))/24) nHoras=alltrim(str(nTotdias-(24*nDias)))+substr(rHoras,at(":",rHoras)) nMeses=int(nDias/30) if nMeses>0 nDias=nDias-(30*nMeses) endif nAnos=int(nMeses/12) if nAnos>0 nMeses=nMeses-(12*nAnos) endif *@09,01 say nAnos *@10,01 say nMeses *@11,01 say nDias *@12,01 say nHoras return({rHoras,alltrim(str(nAnos)),alltrim(str(nMeses)),alltrim(str(nDias)),nHoras}) //return rHoras FUNCTION hh2ss(cHora) *************************************************************************************** *| Empresa.: NSI Softwares e Sites *| Autor...: Anderson Vieira *| Objetivo: Obter a diferenca em segundos entre um periodo. Esta funcao substitui a funcao *| TIMETOSEC() da CATOOLS *| *| objetivo: converte uma hora para segundos ideal para efetuar soma ou subtracao entre horas *| cHora : HH:MM:SS onde HH nao tem limite, ou seja, nao precisa ser ate 23h, pode por exemplo *| ser 1420. A funcao da CT.LIB timetosec() so aceita ate 23h *| retorno : numerico (quantidade de segundos) *************************************************************************************** nSeg=val(substr(cHora,-2,02)) nMin=val(substr(cHora,-5,02))*60 nHor=val(left(cHora,at(":",cHora)-1))*60*60 return nHor+nMin+nSeg FUNCTION ss2hh(cSeg) *************************************************************************************** *| Empresa.: NSI Softwares e Sites *| Autor...: Anderson Vieira *| Objetivo: Obter a diferenca em hora entre um periodo. Esta funcao substitui a funcao *| SECTOTIME() da CATOOLS *| *************************************************************************************** nHor =int(cSeg/3600) rest1=int(cSeg%3600) nMin =int(rest1/60) rest2=int(rest1%60) *? nHor *? rest1 *? nMin *? rest2 *? "----" return alltrim(str(nHor))+":"+padl(alltrim(str(nMin)),2,"0")+":"+padl(alltrim(str(rest2)),2,"0") // FIM DO PROGRAMA Obg. abs. Quote Link to comment Share on other sites More sharing options...
Luiz Fernando Posted June 13, 2013 Report Share Posted June 13, 2013 Ola Kapiaba, precisei disto uma vez, e o ricardo me arrumou a funcao abaixo, funciona 100% function dirfhora(data2,hora2,data1,hora1) private MIN,HOR HOR = val(substr(HORA2,1,2)) - val(substr(HORA1,1,2)) + ((DATA2 - DATA1) * 24) if val(substr(HORA2,4,2)) < val(substr(HORA1,4,2)) HOR = HOR - 1 MIN = val(substr(HORA2,4,2)) - val(substr(HORA1,4,2)) + 60 else MIN = val(substr(HORA2,4,2)) - val(substr(HORA1,4,2)) endif if MIN > 60 MIN = mod(MIN,60) HOR = int(MIN / 60) endif return(iif(HOR>100,strzero(HOR,3)," "+strzero(HOR,2))+":"+strzero(MIN,2)) AbraçosLuiz Fernando Quote Link to comment Share on other sites More sharing options...
sambomb Posted June 13, 2013 Report Share Posted June 13, 2013 Kapiaba, olha aquela classe que te passei no outro post, acredito que nela você consiga tratar isso facilmente. oDtHr1 := TDataHora():New(dData1,cHora1) oDtHr2 := TDataHora():New(dData2,cHora2) nDif := Abs( oDtHr1:Absoluto()-oDtHr2:Absoluto() ) ? "Diferença entre a data 1 e data 2 em segundos = " + AllTrim(Str(nDif)) Edit: nSecsMinuto := 60 //-- FIXO nSecsHora := nSecsMinuto * 60 //-- FIXO nSecsDia := nSecsHora * 24 //-- FIXO nDia := 0 nHora := 0 nMin := 0 cMsg := "" If nDif = 0 cMsg := "nenhuma" end While nDif > nSecsDia nDia++ nDif -= nSecsDia End While nDif > nSecsHora nHora++ nDif -= nSecsHora End While nDif > nSecsHora nMin++ nDif -= nSecsMinuto End If nDia > 0 cMsg += " Dias: " + AllTrim(Str(nDia)) end If nHora > 0 cMsg += " Horas: " + AllTrim(Str(nHora)) end If nMin > 0 cMsg += " Minutos: " + AllTrim(Str(nMin)) end If nDif > 0 cMsg += " Segundos: " + AllTrim(Str(nDif)) end ? "Diferença = " + cMsg Quote Link to comment Share on other sites More sharing options...
ACC69 Posted May 29, 2014 Report Share Posted May 29, 2014 Ola Kapiaba, precisei disto uma vez, e o ricardo me arrumou a funcao abaixo, funciona 100% function dirfhora(data2,hora2,data1,hora1) private MIN,HOR HOR = val(substr(HORA2,1,2)) - val(substr(HORA1,1,2)) + ((DATA2 - DATA1) * 24) if val(substr(HORA2,4,2)) < val(substr(HORA1,4,2)) HOR = HOR - 1 MIN = val(substr(HORA2,4,2)) - val(substr(HORA1,4,2)) + 60 else MIN = val(substr(HORA2,4,2)) - val(substr(HORA1,4,2)) endif if MIN > 60 MIN = mod(MIN,60) HOR = int(MIN / 60) endif return(iif(HOR>100,strzero(HOR,3)," "+strzero(HOR,2))+":"+strzero(MIN,2)) AbraçosLuiz Fernando Hola EMPRESOFT buenos dias como esta!, una pregunta, como es el ejemplo de esta funcion como funciona:. ya que no le hecho andar y ni como es la instruccion para esta funcion. function dirfhora(data2,hora2,data1,hora1) private MIN,HOR HOR = val(substr(HORA2,1,2)) - val(substr(HORA1,1,2)) + ((DATA2 - DATA1) * 24) if val(substr(HORA2,4,2)) < val(substr(HORA1,4,2)) HOR = HOR - 1 MIN = val(substr(HORA2,4,2)) - val(substr(HORA1,4,2)) + 60 else MIN = val(substr(HORA2,4,2)) - val(substr(HORA1,4,2)) endif if MIN > 60 MIN = mod(MIN,60) HOR = int(MIN / 60) endif return(iif(HOR>100,strzero(HOR,3)," "+strzero(HOR,2))+":"+strzero(MIN,2)) Saludos y buen dia.! Quote Link to comment Share on other sites More sharing options...
SAOliveira Posted May 29, 2014 Report Share Posted May 29, 2014 **---------------------------------------------------------**** Finalidade : Retornar intervalo entre dias/horas** Sintaxe : PCS_ElapTime(par1,par2)** Par1 : Dia1/Hora1 DtoC(Dia1)+Subs(hora1,1,8)** Par2 : Dia2/Hora2 DtoC(Dia2)+Subs(hora2,1,8)** Exemplo : PCS_ElapTime(Dia1,Dia2)** Retorno : 00:00:00**---------------------------------------------------------** Function PCS_ElapTime(Data1,Data2)**---------------------------------------------------------**LOCAL D1:=CToD(Subs(Data1,1,10)), H1:=Subs(Data1,11,8)LOCAL D2:=CToD(Subs(Data2,1,10)), H2:=Subs(Data2,11,8)PegaHora:=ElapTime(H1,H2)IF(D2 > D1) PegaDia:=(D2 - D1) * 24 IF(H2 < H1) PegaDia-=24 ENDIF PegaMinuto:=subs(PegaHora,3,6) PegaHora:=Val(Subs(PegaHora,1,2))+PegaDia PegaHora:=AllTrim(Str(PegaHora)+PegaMinuto)ENDIFRETURN(PegaHora) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.