9
I have a project where I must accumulate hours worked of a service in a project, it must store in the bank the hours/days.
So when started, if there is no previous time starts from scratch, but if there has been a step previously it should count from that and time and accumulate, saving later in the bank.
Until then the script is working, but now I need to make it dynamic so that the report appears more than one project showing the execution time.
JS
<script language=JavaScript>
<!-- begin
function getSecs(sDias, sHors, sMins, sSecs, campo, tempo) {
sSecs++;
if (sSecs == 60) {
sSecs = 0;
sMins++;
if (sMins <= 9) sMins = sMins;
}
if (sMins == 60) {
sMins = 0;
sHors++;
if (sHors <= 8) sHors = sHors;
}
//converte para horas trabalhadas, se fossem dias normais seria 24h if(sHors==24){
if (sHors == 8) {
sHors = 0;
sDias++;
}
//corrige com 2 digitos
if (sSecs <= 9) sSecs = "0" + sSecs;
if (sMins <= 9) sMins = "0" + sMins;
if (sHors <= 9) sHors = "0" + sHors;
if (sDias <= 9) sDias = "0" + sDias;
document.getElementById(campo)
.innerHTML = sDias + ":" + sHors + ":" + sMins + ":" + sSecs;
setTimeout("getSecs(" + sDias + ", " + sHors + ", " + sMins + "," + sSecs + ", '" + campo + "')", 1000);
form1.tempo.value = sDias + ":" + sHors + ":" + sMins + ":" + sSecs;
}
//-->
</script>
PHP
<?php
var_dump($_POST);
$data1 = '0,1,59,55';
$data2 = '0,7,59,55';
?>
HTML
<script>
setTimeout("getSecs(<?= $data1 ?>, \"campo1\",'tempo;')", 1000);
</script>
<hr>
<form action="" method="POST" enctype="multipart/form-data" role="form" name="form1">
<input type="text" id="campo1" name="tempo" value="">
<hr>
<input type="submit" value="Enviar" class="btn btn-primary" />
I don’t know about you, but I think it’s the best solution, I found a script interesting of timer, I’ve adapted some of the needs, but I can’t apply more than one input
making the code react dynamically.
I think it would be nice using ajax, then you don’t even need the timer. Also I advise you to use lib momentJs, it facilitates a lot of calculations with date.
– RBoschini
Man how do I do it? Srsrsrsrsrrs
– Bruno Depieri Barduchi
Good to work with ajax?
– RBoschini
n. It took me 2 days to make a 4 script merge to do this rssrsr
– Bruno Depieri Barduchi
You managed to solve?
– durtto
I haven’t been able to
– Bruno Depieri Barduchi
Uses a plugin called Final Countdown. My colleague had to do exactly the same thing. I taught him to do with the
LocalStorage
to store where time "stopped" to proceed later from the same point.– Wallace Maxters
It was bad, actually I used the wrong plugin. What he used calls
Flipclock
. Now you know two :)– Wallace Maxters
I’m gonna test, vlw
– Bruno Depieri Barduchi
If you solved the problem, you can close the question.
– PauloHDSousa
Solved your problem?
– durtto