0 Replies Latest reply on Sep 25, 2013 2:50 PM by Talex904

    What script would I use for a timesheet using 12:00 am?

    Talex904

      I have been able to add a document level script using Acrobat Pro to show midnight as 12:00 am. But my calculations still don't work. As I have it scripted right now a start time of 12:00 am and an end time of 1:00 am equals -11.00 hours not 1.00 hour. What script would I have to add so the calculation is correct?

       

      Here is the script I have right now:

      // start time

      // Start time field name

      var cStartName = "start1mon1";

      // Start time format:

      var cStartFormat = "HH:MM";

      // end time

      // end time field name

      var cEndName = "end1mon1";

      // End time format:

      var cEndFormat = "HH:MM";

      // some conversion functions

      // function to convert time string to minutes

      function Time2Num(cTime, cFormat) {

      // convert time string to minutes

      // convert time string to date object

      var oDate = util.scand("mm/dd/yyyy " + cFormat, "01/01/1970 " + cTime);

      // convert date object to number of milliseconds

      var nTime = oDate.getTime();

      // convert milliseconds to minutes and return value

      return Math.round(nTime / (1000 * 60));

      } // end Time2Num function

      function Num2Time(nMinutes) {

      // convert time string to Hours and Minute

      // hours in nMinues

      var nHrs = Math.floor(nMinutes / 60);

      // remainder minutes from hours in nMinutes

      var nMins = nMinutes / 60;

      // return formatted time string

      return nHrs, nMins;

      } // end Num2Time

      // end conversion functions

      // perform the calculation using the fields:

      // get the values of the fields

      var cStartTime = this.getField(cStartName).value;

      var cEndTime = this.getField(cEndName).value;

      // clear the value

      event.value = "";

      // test for not null time strings

      if(cStartTime != "" && cEndTime != "") {

      // compute the time difference in minutes

      nDiff = Time2Num(cEndTime, cEndFormat) - Time2Num(cStartTime, cStartFormat);

      event.value = Num2Time(nDiff);

      } //end not null values

       

      I have no prior knowledge of JavaScript, only what I have found here on the forums and a lot of luck. I would appreciate help on this problem. Thanks!