Timesheet Calculation Javascript
- July 18, 2022
- 2 replies
- 1866 views
Hello there, I know that there are multiple chains on this but I am struggling to combine a few aspects of the timecode. Inserting a picture. Essentially trying to write a script for the difference between hours worked minus a lunch break. Also trying to have the calculation boxes come up as blank if no time is input. (Also trying to avoid having lunch in and out times)
This is what I have - can someone advise? A quick solution would be much appreciated
// start
var start = this.getField("1").valueAsString
var startArr = start.split(":");
// finish
var finish = this.getField("3").valueAsString;
var finishArr = finish.split(":");
// lunchbreak
var lunchbreak =this.getField("2").valueAsString
var lunchbreakArr = finish.split(":")
//blanknotfilled
if (start=="" || finish=="") event.value = ""
else {
// difference
var hourDiff = (Math.abs(finishArr[0] - startArr[0])) - lunchbreakArr[0];
var minDiff = Math.floor(((Math.abs(finishArr[1] - startArr[1])- lunchbreakArr[0])/ 60)*100);
if (minDiff.toString().length == 1)
minDiff = '0' + minDiff;
var output = hourDiff + "." + minDiff;}
