## Function for timesheet calculation

New Here ,
Mar 25, 2019

Copied

Hi Guys,

I wanted to know, Is it possible to create a Javascript Function based calculation for a timesheet that also includes amount of people working during that time period.

Example.

StartFinishNumber of workersTotal Hours
Start1.0Finish1.0Workers1.0Totalhours1.0
Start1.1Finish1.1Workers1.1Totalhours1.1
Start1.2Finish1.1Workers1.2Totalhours1.2

My function would be something like CalcHours() …..   which would yield something like would calculate like this (Finish1.0 - Start1.0) * Workers1.0

your helps would be greatly appreciated.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

213

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

## Function for timesheet calculation

New Here ,
Mar 25, 2019

Copied

Hi Guys,

I wanted to know, Is it possible to create a Javascript Function based calculation for a timesheet that also includes amount of people working during that time period.

Example.

StartFinishNumber of workersTotal Hours
Start1.0Finish1.0Workers1.0Totalhours1.0
Start1.1Finish1.1Workers1.1Totalhours1.1
Start1.2Finish1.1Workers1.2Totalhours1.2

My function would be something like CalcHours() …..   which would yield something like would calculate like this (Finish1.0 - Start1.0) * Workers1.0

your helps would be greatly appreciated.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

214

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 25, 2019 0
7 Replies 7
Guide ,
Mar 26, 2019

Copied

Is there a particular reason to use a Javascript function for this simple calculation? Otherwise just use a Simplified Notation calculation field for your total hours field with this formula:

((finishTime - startTime)*numberOfWorkers)

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 26, 2019 0
Most Valuable Participant ,
Mar 27, 2019

Copied

The reason is it won't work that way... Time calculations require using a script.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 27, 2019 0
New Here ,
Mar 27, 2019

Copied

TRy67, do you think you would know how to solve this? you seem like you know your stuff.

Many people would appreciate it.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 27, 2019 0
Most Valuable Participant ,
Mar 27, 2019

Copied

I've developed a (paid-for) tool that allows you to set up such calculations very easily. You can find it here: Custom-made Adobe Scripts: Acrobat -- Calculate Time Differences in a Worksheet

Once you've calculated the difference between the two time fields multiplying it by the number of workers is trivial.

If you're interested I could set it all up for you (for a fee). You can contact me privately (try6767 at gmail.com) to discuss it further.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 27, 2019 0
Guide ,
Mar 28, 2019

Copied

 try67  wroteThe reason is it won't work that way... Time calculations require using a script.

Oops, that's true. Been a while since I worked with PDF forms.

// document functions

function HHMM2Min(cTime) {

var aHHMM = cTime.split(":");

var nMinutes = 0;

nMinutes = aHHMM[0] * 60;

nMinutes += Number(aHHMM[1]);

return nMinutes;

}

function Min2HHMM(nMinutes) {

return util.printf("%,001.0f:%,202.0f", Math.floor(nMinutes / 60), nMinutes % 60);

}

function calcHours(startTime,endTime,numberOfWorkers) {

var minStart = parseInt(startTime.split(":")[1]);

var hrsEnd = parseInt(endTime.split(":")[0]);

var minEnd = parseInt(endTime.split(":")[1]);

if (minStart > minEnd) {

var minRez = 60 + minEnd - minStart;

var hrsRez = hrsEnd - 1 - hrsStart;

}

else

{

var minRez = minEnd - minStart;

var hrsRez = hrsEnd - hrsStart;

}

timeTotal = hrsRez + ":" + minRez;

sTime = timeTotal;

nSum = HHMM2Min(sTime) * numberOfWorkers;

totalHours = Min2HHMM(nSum);

}

//calc field

timeStarted = this.getField('timeIn').value;

timeFinished = this.getField('timeOut').value;

workerNumber = this.getField('multiplier').value;

event.value = calcHours(timeStarted, timeFinished, workerNumber);

It does what you want, I think. I only tested with one timeIn time input field, one timeOut input field, and one multiplier (workers) field.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 28, 2019 0
Mar 28, 2019

Copied

Your script will not work correctly if the time interval you are trying to compute includes the change in Daylight Savings time. If you time sheet will include that time, then you must include the date since the time change occurs on very specific days. JavaScript will know the dates and time based on the timezone setting of your computer.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 28, 2019 0
LATEST
Guide ,
Mar 28, 2019

Copied

Yeah, I realized that this morning as well while looking at it with fresh eyes. Initially I assumed the OP wanted a simple hours a day worked, but re-reading the OP's question, he mentions a 'time period' which probably should include a full date & time object.

Back to the drawing board, if I can find the time. Or it might resolve itself if we wait long enough for all countries to abolish daylight savings

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 28, 2019 0