• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Function for timesheet calculation

New Here ,
Mar 25, 2019 Mar 25, 2019

Copy link to clipboard

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

570

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Mar 26, 2019 Mar 26, 2019

Copy link to clipboard

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 27, 2019 Mar 27, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Many people would appreciate it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 27, 2019 Mar 27, 2019

Copy link to clipboard

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

try67  wrote

The 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.

How about this hacked together script:

// 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 hrsStart = parseInt(startTime.split(":")[0]);

    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);

    return totalHours;

}

//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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

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