Skip to main content
joshg50430556
Participant
March 31, 2019
Question

Time sheet per single calendar day - Adobe Acrobat X

  • March 31, 2019
  • 4 replies
  • 1236 views

Good evening,

I built the attached form using gkaiseril code and it works awesome! I have only two modifications I would like to make but, unsure how to complete the task.

1. I would like to define the time format to ensure the user follows the 12-hour format using am and pm. The time sheet needs to work at 12:00am and I would like it to display 12:00am instead of 00:00. Some users might think 00:00 is the end of the world or something . As you can see I purposely moved the am and pm over a space in a couple of fields. I would like each field to be consistent.

2. Using the script, I have the totals working in decimal hours. I would also like to show totals in hours and minutes.

This time sheet is per calendar day so the date field is not really relevant in my opinion.

Thank you in advance for your help!!!

Josh

Time Sheet Image:

Script:

//-------------------------------------------------------------

//-----------------Do not edit the XML tags--------------------

//-------------------------------------------------------------

//<Document-Level>

//<ACRO_source>Round</ACRO_source>

//<ACRO_script>

/*********** belongs to: Document-Level:Round ***********/

function Round(nValue, nPrecision) {

// round a number a given precision

return util.printf("%,1 0." + nPrecision + "f", nValue);

} // end round

//</ACRO_script>

//</Document-Level>

//<Document-Level>

//<ACRO_source>Time2MinRE</ACRO_source>

//<ACRO_script>

/*********** belongs to: Document-Level:Time2MinRE ***********/

function Time2MinRE(cTime){

// convert time string h:MM tt or HH:MM to minutes

var min = 0

if ( /(\d{0,2})[:](\d{2})[ ]?([ap])/i.test(cTime) ) {

// civilian time

if(RegExp.$1 != 12)

min = 60 * RegExp.$1; // hour not 12

min += Number(RegExp.$2);

if (RegExp.$3 == "p")

min += 12 * 60; // adjust for time after 11:59.999 am

}

else if (/(\d{0,2})[:](\d{2})/.test(cTime)) {

// military time

min = 60 * Number(RegExp.$1);

min += Number(RegExp.$2);

}

return min;

} // end function Time2MinRE

//</ACRO_script>

//</Document-Level>

//<AcroForm>

//<ACRO_source>decimal_hours_1:Calculate</ACRO_source>

//<ACRO_script>

/*********** belongs to: AcroForm:decimal_hours_1:Calculate ***********/

(function () {

event.value = "";

// get time out

var sOut = this.getField('out_time_1').value;

// get time in

var sIn = this.getField('in_time_1').value;

// compute only if we have data

if(sOut != "" & sIn != "") {

// convert time out to minutes

var nOutMin = Time2MinRE(sOut);

// convert time in minutes

var nInMin = Time2MinRE(sIn);

// compute difference

var nDiff = nOutMin - nInMin;

// convert to hours

nDiff = nDiff / 60;

// round to 2 decimal places

event.value = Round(nDiff, 2);

}

return;

}) ();

//</ACRO_script>

//</AcroForm>

//<AcroForm>

//<ACRO_source>decimal_hours_2:Calculate</ACRO_source>

//<ACRO_script>

/*********** belongs to: AcroForm:decimal_hours_2:Calculate ***********/

(function () {

event.value = "";

// get time out

var sOut = this.getField('out_time_2').value;

// get time in

var sIn = this.getField('in_time_2').value;

// compute only if we have data

if(sOut != "" & sIn != "") {

// convert time out to minutes

var nOutMin = Time2MinRE(sOut);

// convert time in minutes

var nInMin = Time2MinRE(sIn);

// compute difference

var nDiff = nOutMin - nInMin;

// convert to hours

nDiff = nDiff / 60;

// round to 2 decimal places

event.value = Round(nDiff, 2);

}

return;

}) ();

//</ACRO_script>

//</AcroForm>

//<AcroForm>

//<ACRO_source>decimal_hours_3:Calculate</ACRO_source>

//<ACRO_script>

/*********** belongs to: AcroForm:decimal_hours_3:Calculate ***********/

(function () {

event.value = "";

// get time out

var sOut = this.getField('out_time_3').value;

// get time in

var sIn = this.getField('in_time_3').value;

// compute only if we have data

if(sOut != "" & sIn != "") {

// convert time out to minutes

var nOutMin = Time2MinRE(sOut);

// convert time in minutes

var nInMin = Time2MinRE(sIn);

// compute difference

var nDiff = nOutMin - nInMin;

// convert to hours

nDiff = nDiff / 60;

// round to 2 decimal places

event.value = Round(nDiff, 2);

}

return;

}) ();

//</ACRO_script>

//</AcroForm>

//<AcroForm>

//<ACRO_source>out_time_1:Format</ACRO_source>

//<ACRO_script>

/*********** belongs to: AcroForm:out_time_1:Format ***********/

// Do regular formattingcFmtData = util.printd("timeout",myTime);if(myTime.getHours() == 0){// 12 midnight, replace "00" with 12cFmtDate =  cFmtDate.replace(/00\:/,"12:");}

//</ACRO_script>

//</AcroForm>

//<AcroForm>

//<ACRO_source>out_time_2:Format</ACRO_source>

//<ACRO_script>

/*********** belongs to: AcroForm:out_time_2:Format ***********/

// Do regular formattingcFmtData = util.printd("timeout",myTime);if(myTime.getHours() == 0){// 12 midnight, replace "00" with 12cFmtDate =  cFmtDate.replace(/00\:/,"12:");}

//</ACRO_script>

//</AcroForm>

//<AcroForm>

//<ACRO_source>out_time_3:Format</ACRO_source>

//<ACRO_script>

/*********** belongs to: AcroForm:out_time_3:Format ***********/

// Do regular formattingcFmtData = util.printd("timeout",myTime);if(myTime.getHours() == 0){// 12 midnight, replace "00" with 12cFmtDate =  cFmtDate.replace(/00\:/,"12:");}

//</ACRO_script>

//</AcroForm>

//<AcroForm>

//<ACRO_source>todays_date:Annot1:MouseUp:Action1</ACRO_source>

//<ACRO_script>

/*********** belongs to: AcroForm:todays_date:Annot1:MouseUp:Action1 ***********/

this.getField("date").value = util.printd("mmm d, yyyy",new Date());

//</ACRO_script>

//</AcroForm>

This topic has been closed for replies.

4 replies

joshg50430556
Participant
April 21, 2019

Hi test screen name, Understood, I am looking to learn but, I do not understand Try67's comments. I have the form almost to where it completely works! I just don't know how to get over the last hurdle. If you can show me in the code where to modify it I will do it myself. I am a visual learner.

I built this PDF from reading numerous posts on this forum as well as around the internet.

I am also hopefully this post will help other folks on this forum to build out their version utilizing good code.

Thank you for your reply,

Josh

joshg50430556
Participant
April 21, 2019

I am looking for assistance in writing the code to complete this form as described above. As I originally posted, I am using gkaiseril code since I do not have advanced java scripting knowledge to complete this form.

Legend
April 21, 2019

We don’t like to just write code for people. Often they learn nothing from this except where to ask, and little by little they expect us to do their whole project.

So please try. Show us what you have and let us correct and teach you, so you will have more skills in future, thanks. Please don’t post such long code unless asked though.

joshg50430556
Participant
April 21, 2019

Yes, I would like it to read 12:00am not 00:00.

I would like one column to show hours/minutes the other column decimal hours.

The bottom fields will show the totals.

thank you,

josh

try67
Community Expert
Community Expert
April 21, 2019

You're just repeating what you wrote before...

joshg50430556
Participant
April 20, 2019

Good evening,

I haven't heard from anybody on this forum as of yet. I could really use the help to solve this issue.

Thank you,

Josh

try67
Community Expert
Community Expert
April 20, 2019

1. Not possible. You will need to write your own time code to allow it. I think most people know what 00:00 mean, though...

2. So instead of 1.5 you want to display 1:30? If so, you'll need to split the value into the integer part and the decimal part, and multiple the latter by 60 to get the number of minutes, then re-combine them as a string, separated by a colon.

In the future it will be helpful to keep your questions short and concise.