These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Timesheet auto calc 4 fields

digitalwiz
Registered: Mar 9 2011
Posts: 20

Hi,
 
I'm developing our timesheet with 4 input fields and a 5th total field.
 
Using Adobe pro 9.
 
field names:
 
In1 Out1 In2 Out2 Total1
 
or (Out1 - In1) + (Out2 - In2) is in my simplified field notation for the Total1 field.
 
format is HH:MM for all in and out fields. Format is numeric, 2 decimal for total1.
 
my issue is that it will not calculate time correctly in small increments.
 
so calculating anything less than quarter hours doesnt represent time correctly.
 
for instance: 8:05 - 12:00 + 1:00 -4:00 gives 6.95. our payroll person cannot work with 6.95 and would prefer it be 6:55.
 
i do understand that im not formating the total1 field for time. thats because it doesnt do anything at all when i do.
 
any suggestions?
 

thanks

My Product Information:
Acrobat Pro 9.4.3, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
The time format assumes you are dealing with modular (circular) time values for the minutes. The minutes value has to be between 0 and 59, since this is the number minutes in any one hour.

What are your scripts for this calculation?

I find that the following document level functions:

function Time2Min(cTime){
// convert time string h:MM tt or HH:MM to minutes
var min = 0
// civilian time
if (/(\d{0,2})[:](\d{2})[ ]([AaPp])/.test(cTime)) {
if (RegExp.$3.toLowerCase() == "p")
RegExp$1 += 12;
min = 60 * Number(RegExp.$1);
min += Number(RegExp.$2);
} else {
// military time
if (/(\d{0,2})[:](\d{2})/.test(cTime)) {
min = 60 * Number(RegExp.$1);
min += Number(RegExp.$2);
}
}
return min;
} // end Time2Min function

function Min2HHMM(nMinutes) {
// round to whole minutes
nMinutes = Math.round(nMinutes);
// compute whole hours
var nHrs = Math.floor(nMinutes / 60);
// compute remainder minutes
var nMins = Math.round(nMinutes % 60);
// return formatted string
return nHrs + ":" + util.printf("%,002.0f", nMins);
} // end Min2HHMM function

Along with this custom field calculation script:

// minutes worked
var nMinWorked = 0;

// interval 1
var In = this.getField('In1').valueAsString;
var Out = this.getField('Out1').valueAsString;
if(In != '' & Out != '')
nMinWorked += Time2Min(Out) - Time2Min(In);

// interval 2
var In = this.getField('In2').valueAsString;
var Out = this.getField('Out2').valueAsString;
if(In != '' & Out != '')
nMinWorked += Time2Min(Out) - Time2Min(In);

// format output
event.value = Min2HHMM(nMinWorked);

Work for me.

You might want to consider using the 24 hour format or include the am/pm indicator in your inputted time formats.





George Kaiser

digitalwiz
Registered: Mar 9 2011
Posts: 20
i have no other "scripts" than what i posted. just the (Out1 - In1) + (Out2 - In2) in the simple notation field.

If i can just copy and paste what you typed where would i paste it into? the Total1 or in each base field out1, In1 out2 in2...

Im no expert at java or sfn so im looking for explicit instructions if you have the time and inclination to help.

thanks so much...

thanks

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You should not be able to use the 'Simplified Field Notation' but it appears Acrobat does not convert the time string properly to a a number that represents a time interval. That option is converting the ":" separator into a decimal point so you are computing (11.00 - 8.05) + (4.00 - 1.00) and not the time values. If I were to convert the time inputs to minutes, then the decimal fraction hours should have been 6.92 hours.

See How to do (not so simple) form calculations and Entering Document Scripts by Thom Parker.

George Kaiser

digitalwiz
Registered: Mar 9 2011
Posts: 20
thank you George,

Unfortunately its all gibberish to me. Like i stated above i'm looking for a formula to address my issue if there is one.

I'm not looking to become an expert at Java Scripting. I have review both of those links before and they have not been helpful to me. Either i already understand the concept (sfn) or its way beyond my skill level (java).

If you have a formula for me to paste into my Total1 field that correctly calculates time additions down to the minute or 5 minute level i'll happily give it a try otherwise i guess i'll have to abandon this part of this project.

Anyone have any suggestions or calculations to try?

thanks

try67
Expert
Registered: Oct 30 2008
Posts: 2398
If you're interested, I've created a script that will automatically do it for you:
http://try67.blogspot.com/2011/03/acrobat-calculate-time-differences-in.php

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com