Copy link to clipboard
Copied
I have a fillable pdf set up for technicians daily activities. Part of this is daily time. I have start time hours, start time minutes, Start time AMPM, break, end time hours, end time minutes, end time AMPM. I used Thom's script calculates time worked correctly but when the boxes are empty, the total worked displays 24.
//Get Time Values
var StartTimeHour = this.getField("STH1").value;
var StartTimeMin = this.getField("STM1").value;
var StartTimeAP = this.getField("STAP1").value;
var EndTimeHour = this.getField("ETH1").value;
var EndTimeMin = this.getField("ETM1").value;
var EndTimeAP = this.getField("ETAP1").value;
var BreakTime = this.getField("Break1").value;
//Combine Time Values
var StartTime = (StartTimeHour + StartTimeMin + StartTimeAP);
var EndTime = (EndTimeHour + EndTimeMin + EndTimeAP);
//Calculate Time
var TimeWorked = ((EndTime - StartTime) - BreakTime);
//Test for Midnight Crossover
if(TimeWorked < 0) {// Shift 24 hours
TimeWorked += 24;
} else if(TimeWorked === 0) {//Shift 24 hours for same times
TimeWorked += 24;
}
//Print Results
event.value = TimeWorked;
The Option values for hours are set up 1=1-11=1 12=0. My minutes are 00, 15, 30, 45. AM PM is 0 and 12
I do have blanks in the options so the boxes are empty when not in use
Copy link to clipboard
Copied
Can the times be more than 24 hours apart? If so, you have to include the full date, as well.
Otherwise the script can't know if 9:00-10:00 means 1 hour, 25 hours, 49 hours, etc.
Copy link to clipboard
Copied
We run 2 shifts. ^:00 AM to 4:00 PM and 7:30 PM to 7:00 AM
Copy link to clipboard
Copied
6:00 AM to 4:00 PM
Copy link to clipboard
Copied
Then you don't need this condition at all:
else if(TimeWorked === 0) {//Shift 24 hours for same times
TimeWorked += 24;
}