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

Timesheet Hours Worked Will Not Display Correctly

Community Beginner ,
Sep 19, 2017 Sep 19, 2017

Copy link to clipboard

Copied

I'm using Adobe Acrobat Pro DC.

I have four fields [amIN0, amOUT0, pmIN0, and pmOUT0] that will auto-populate the Hours Worked field.

My times are formatted to h:MM tt.

I need the HoursWorked results to display 7 hours and 30 minutes as 7.50 NOT 7.30

And 8 hours and 30 minutes should display as 8.50 NOT 8.70

I'm using a simplified notation (amOUT0-amIN0)+(pmOUT0-pmIN0).

Please help. Thank you.

timesheet.png

TOPICS
Acrobat SDK and JavaScript , Windows

Views

636

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

correct answers 1 Correct answer

Community Expert , Sep 20, 2017 Sep 20, 2017

Change the last line of the Regular Hours calculation to:

event.value = Math.min(40, normalHours, totalHours);

Votes

Translate

Translate
Community Expert ,
Sep 19, 2017 Sep 19, 2017

Copy link to clipboard

Copied

You can't do it like that. Time calculations are much more complex than normal math calculations, and require a custom-made script.

There are good tutorials about this subject here:

https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript

https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript-part-2

https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript-part-3

Alternatively, if you don't want to write the code yourself, I've developed a tool that allows you to easily set up this kind of calculation, including the option to show the result in decimal format (ie, 2.5 for two and a half hours, instead of 2:30): Custom-made Adobe Scripts: Acrobat -- Calculate Time Differences in a Worksheet

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 Beginner ,
Sep 19, 2017 Sep 19, 2017

Copy link to clipboard

Copied

Yes, this all seems very complex as I am new to javascript.

However, I've run into another snag.  Hopefully, it is a small fix. The Regular Hours cannot exceed 40 hours. Regular and Overtime should equal Total Hours Worked. What do I need to change to make this work?

This is the custom script for Regular Hours:

var normalHours = Number(this.getField("NormalHours").value);

var totalHours = Number(this.getField("TotalHours").value);

event.value = Math.min(normalHours, totalHours);

This is the custom script for Overtime Hours:

event.value = +this.getField("TotalHrsWorked").value > 40 ? (+this.getField("TotalHrsWorked").value - 40) : 0;

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 ,
Sep 20, 2017 Sep 20, 2017

Copy link to clipboard

Copied

Change the last line of the Regular Hours calculation to:

event.value = Math.min(40, normalHours, totalHours);

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 Beginner ,
Sep 21, 2017 Sep 21, 2017

Copy link to clipboard

Copied

Thank you very much. That worked.

I still have to devote some time to the other columns. I will look at the links provided and if I cannot figure it out, I will try your tool. I greatly appreciate the help.

Thanks!.

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 ,
Sep 22, 2017 Sep 22, 2017

Copy link to clipboard

Copied

LATEST

I would convert all the in and out times to the number of minutes from the Epoch date and compute the time worked. I would use the "Format" tab to convert the number of minutes worked to the desired display format, since the displayed format does not change the value of the field. One then use the standard mathematical operators on the number of minutes without any changes.

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