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

Another Formula Question

MetroTraveler
Registered: Feb 13 2011
Posts: 6

My prior question on elapsed time was answered quickly and correctly - thanks!
 
I am working on a form that is used to bill insurance companies for therapeutic services. Time is billed in units of service. 1 unit of service is equal to 15 minutes. The problem is the time of actual contacts often falls slightly below or above a 15 minute increment. For example, a 25 minute contact equals 2 units of service. A 35 minute or 30 minute contact also equals 2 units of service. At the same time, any contact over 8 minutes also equals a unit of service.
 
I am looking for a formula that will automatically round up or down the actual time billed into the appropriate units of services. For example, 1:40 (1 hour, 40 minutes) will automatically round up to 7 units of service rather than 6.66 units.
 
The "Total time billed" is in one field and the "Units" are in another field. The Total Time billed is in an HH:MM format rather than minutes only. For example, 100 minutes comes up as 1:40. Does anyone have an idea of a formula that will work?
 
Thank you. The help provided earlier was much appreciated.
 

My Product Information:
Acrobat Pro 9.4, Macintosh
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You need to better define your requirements. Why is 25 minutes 2 units and 35 also 2 units? How do you decide when to round up and when to round down?

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

MetroTraveler
Registered: Feb 13 2011
Posts: 6
Here is the deal:

For anything over 8 minutes, we round up to 1 unit; however, we still need to keep the time as 8 mnutes. We cannot change the actual time billed.

Therefore, 8 minutes is where we decide to round up. For example, an 8 minutes contact will be billed as 1 unit, a 23 minute contact will be billed as 2 units, a 38 minute contact will be billed as 3 units, a 53 minute contact is billed as 4 units, etc.

Rounding down works the same way, a 7 minute contact is billed as 0 units, a 22 minute contatc is billed as 1 unit, a 37 minute contact is billed as 2 units, a 52 minute contact is billed as 3 units, etc.

Does this make sense?
try67
Expert
Registered: Oct 30 2008
Posts: 2398
This should work as the custom calculation script for the Units field:

tTime = this.getField("Total time billed").value;
if (tTime!="") {
tTimeHours = Number(tTime.split(":")[0]);
tTimeMinutes = Number(tTime.split(":")[1]);
tTimeMinutes += (60*tTimeHours);
units = Math.floor(tTimeMinutes/15);
if ((tTimeMinutes%15)>=8) units++;
event.value = units;
} else event.value = "";

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

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You are rounding to the quarter hour of nearest 15 minutes.

I would use some function. 1 to format the HH:MM string to minutes, and one to format minutes to HH:MM.

You can use the Math.round method to round the elapsed minutes into 15 minutes units rounded up at the 7.5 minute break point and down when below 7.5 minutes.

// document level function
function HHMM2Min (sTime) {
// convert HH:MM string to total minutes
// get hours and minutes
var aTime = sTime.split(":");
// return minutes only
return (aTime[0] * 60) + Number(aTime[1]);
}


// document level function
function Min2HHMM (nMin) {
// convert minutes to string of HH:MM
// format whole hours with leading zero
var sHours = util.printf("%,002.0f", Math.floor(nMin / 60));
// format minutes with leading zero
var sMin = util.printf("%,002.0f", nMin % 60);
// return formatted string
return sHours + ":" + sMin;
}


// custom calculation script
// get start time in minutes
var StartMin = HHMM2Min(this.getField('StartTime').value);
// get end time in minutes
var EndMin = HHMM2Min(this.getField('EndTime').value);
// compute elapsed minutes
var DiffMin = EndMin - StartMin;
// compute 15 minute units from the elapsed minutes
var nUnits = Math.round(DiffMin / 15)
// format elapsed time in HH;MM
var sElapsed = Min2HHMM(DiffMin);

console.show();
console.clear();
// display units
console.println('Units: ' + nUnits);
// display elapsed time
console.println('Elapsed time: ' + sElapsed )

George Kaiser

MetroTraveler
Registered: Feb 13 2011
Posts: 6
I'm at work now and do not have access to my computer. I'll try it out later tonight and let you know how it goes. thanks