1 Reply Latest reply on May 15, 2013 12:36 PM by gkaiseril

    Timesheet script to calculate break and overtime

    Greg Nygren

      I am working on a fillable Timesheet for use on IOS or PC  and I am hoping that one of you experts might be able to help as I am having  difficulties finishing this script    here is a link to the file I am working on if you want to  look at it      https://www.dropbox.com/s/0sxdlmfjvax07la/Form%20-%20Timesheet%20Fillable.pdf    So far the RegTime.1(decimal number) field is calculating  time ok but I need to incorporate the following    1)  I Have a variable field called RegHours that defaults to 8. if this field has 8 then anything  over will go to another field OverTime.1    2)  I also have a decimal number field  called  BreakTime.1  that needs to be deducted  from the total     3) one other thing is that if I go past midnight my total  goes to negative number. I'm just wondering if a simple solution to this would  be to add 12 if the result is less than 0    //RegTime.1 Field Calculation Script var cIn = "StartTime.1", cOut = "StopTime.1";    event.value = TimeDiff("HH:MM", cIn, cOut);-Breaktime1  // convert zero entry to null  if(event.value == 0) event.value = "";     //OverTime.1 Field Calculation Script   not written yet    Any help you can give will be greatly appreciated     Greg

       

      Message was edited by: Greg Nygren

       

      Message was edited by: Greg Nygren

       

      Message was edited by: Greg Nygren

       

      Message was edited by: Greg Nygren

        • 1. Re: Timesheet script to calculate break and overtime
          gkaiseril MVP & Adobe Community Professional

          Since you are using drop down boxes, you could use the export value to be the minutes from midnight for each option. This would simplify your time calculation, as you would not need to convert a time string to minutes from midnight of the epoch date.

           

          // variables for time field names used in calculation;

          var cIn = "StartTime.1.0"

          var cOut = "StopTime.1.0";

          var cBreak = "BreakTime.1.0";

          // compute total time worked in minutes

          var nTotalMin = this.getField(cIn).value - this.getField(cOut).value - this.getField(cBreak).value;

          // time worked over 8 hours or 480 minutes;

          if(nTotalMin > 480) {

          // set over time value;

          // set regular time to total min - 480;

          } else {

          // set regular time to nTotalMin;

          }

           

          I would use the format for the field to format the total minutes to hours and decimal minutes.