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

JavaScript for Calculating Average Time

New Here ,
Feb 18, 2020 Feb 18, 2020

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!

TOPICS
Acrobat SDK and JavaScript
1.3K
Translate
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 ,
Feb 18, 2020 Feb 18, 2020

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?

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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 ,
Feb 18, 2020 Feb 18, 2020

Either, honestly! I am interested in learning in the long run, but I need to turn this project over rather quickly.

Translate
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 ,
Feb 18, 2020 Feb 18, 2020
No - not yet. Still a newbie.
Thanks, Sasha
Translate
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 ,
Feb 18, 2020 Feb 18, 2020

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?

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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 Beginner ,
Feb 18, 2020 Feb 18, 2020

This article might not be specifically about what you are looking for but the functions used might be a good start.

Translate
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 Beginner ,
Feb 18, 2020 Feb 18, 2020
LATEST

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

Translate
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