问题
First, I give thanks to ksav and his help thus far.
I'm a foreman for a landscaping company and it's my responsibility to fill out forms for each site and keep track of our man hours so we don't go over the allotted time. I'm trying to digitize the documents in Adobe so I can enter the times in the field on my phone without pen and paper and have a JavaScript code automatically calculate the hours on site in decimal format.
Note: I will be using 24-hour time aka military time (13:00/1PM 16:40/4:40PM)
The JS code currently used within Adobe isn't calculating/converting the time difference correctly:
This gives incorrect decimal calculations on the time difference:
var start = this.getField("Monday Site #1 Start Time").value;
var startArr = start.split(":");
// finish
var finish = this.getField("Monday Site #1 Depart Time").value;
var finishArr = finish.split(":");
// difference
var hourDiff = Math.abs(finishArr[0] - startArr[0]);
var minDiff = Math.floor((Math.abs(finishArr[1] - startArr[1]) / 59)*100);
if (minDiff.toString().length == 1)
minDiff = '0' + minDiff;
var output = hourDiff + "." + minDiff;
event.value = output;
if ((event.value == "") || (event.value == Infinity) || isNaN(event.value))
{event.value = "";}
Examples of the hour-decimal calculation errors:
I should mention these fields are all uniquely named Form Fill fields within Adobe, hence the variable field names "Monday Site #1 Start Time, Monday Site #1 Depart Time, MS1 Total Hours etc etc:
See my original question where I tried other JS code to no avail. Some of those snippets didn't give me any value whatsoever
I have limited knowledge on JavaScript code so any assistance with this would be greatly appreciated!
来源:https://stackoverflow.com/questions/58683495/miscalculation-of-decimal-hours-worked-via-javascript-in-adobe-form-fill