JavaScript for Calculating Average Time
Copy link to clipboard
Copied
I am trying to create a custom calculation script that will calculate an average using the HH:MM:ss format in a fillable PDF. The form has 12 fields to enter a time in the HH:MM:ss format, and I need to create a field that will average those 12 fields, and omit the fields that have nothing entered. I am familiar with javascript, but have never written. Can someone please help?
Thanks in advance!
Copy link to clipboard
Copied
Are you interested in learning JavaScript? Would you like some direction on how to start on a solution? Or do you just want someone to write the script for you?
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Either, honestly! I am interested in learning in the long run, but I need to turn this project over rather quickly.
Copy link to clipboard
Copied
Thanks, Sasha
Copy link to clipboard
Copied
For this solution you don't need to use the date object. It's just calculating an average.
The method is to
1) break time format text into parts
2) convert to seconds
3) add them all up and calculate average
4) convert average to the time format.
This is not a particularly onerous problem, but it takes some time and effort to do. And there are some issues.
1) What are the field names? They need use group nameing, for example: "Time.Entry1", "Time.Entry2" etc.
2) What is done with fields that are not filled in? are they considerd a 0 in the average? or are they not counted?
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
This article might not be specifically about what you are looking for but the functions used might be a good start.
Copy link to clipboard
Copied
These are good snipped of code to get date time average, specially if you need to calculate time between a range of dates... the article has code snipped for both, averaging time within a day or different dates. But be aware that not all JavaScript functions will work as expected in Acrobat JS so might take some research..

