Miscalculation of decimal hours worked via JavaScript in Adobe Form Fill

泄露秘密 提交于 2020-01-13 06:46:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!