2 Replies Latest reply on Mar 21, 2015 3:56 PM by KAL46

    Javascript Calculations for Timesheet


      Hi, Sorry if this question seems like a commonly asked one but after looking for about a day at lots of posts and a lot of googling I am still lost.


      Attached is a Journey Log (essentially a timesheet) which I need to do the following:

      Dropbox - New E190 v3 fillable.pdf


      • BLK = ATA-ATD for each row (eg. actual time departure 1100 actual time arrival 1156 = Block time 0:56) - Tried this on simple calculation and just doesn't work. Ideally though times entered should be HHMM and calculated duration should be H:MM (no preceding 0 for hours), as example.


      • TOTAL BLK = SUM(BLK1:BLK6) for each row (eg. 0:56, 1:06 = 2:02) - I tried this on the simple calculations but get an error that formats are not the same, but they are.


      These are simple and I thought could be done in the "simplified field notation" of the calculate tab. I don't understand why they won't work.


      The complicated one is as follows - for each horizontal line:



      so, latest off duty minus earliest on duty less the rest period (split times), if applicable



      • DUTY ON and OFF times will always be filled in
      • SBY (standby) times can be blank and so should not affect the minimum/maximum on and off duty times
      • SPLIT times will not always be filled in, but if filled in will both be completed.
      • Any times could run over midnight
      • Start day would be the DATE which is entered as DD/MM/YYYY
      • End day will always be no later than the next day.
      • Ideally times entered should be HHMM and duration calculated should be H:MM (no preceding 0 on hours)


      This could, if it has to be, just be OFFDUTY-ONDUTY if the TOTAL text area that calculates it could be overridden in the event of other entries. I don't know if this is possible?




      I would appreciate any help with this. I tried with some Javascript (you will see I started to build the basics in the calculation fields - but couldn't even get that working). My knowledge of Javascript is very basic and so with the adobe differences and dealing with time in Javascript I just can't get it figures out.

        • 1. Re: Javascript Calculations for Timesheet
          gkaiseril MVP & Adobe Community Professional

          Since when has date and time calculations ever been simple?


          It is about as simple as computing using imperial measurements.


          One needs to convert the start date and start time into the JavaScript date object using Acrobat JavaScript's "util.scand" method. From the date object one can get the number of milliseconds since the Epoch date, January 1, 1970, and that can be converted to hours or minutes. Once you have the start time and end time length in minutes from the Epoch date, subtracting the start minutes from the end minutes will result in the elapsed minutes if both times occur within the same date.


          it might be more complicated when the start and end times are on different dates. Your assumption that start and end times would occur within 24 hours could be false. I am aware of at least one case where a flight in a passenger DC10 took over 24 hours total time because of weather delays after the start of the flight. You might want to provide a mechanism to indicate that the end time is the next day from the start date.

          • 2. Re: Javascript Calculations for Timesheet
            KAL46 Level 1

            Thanks for the reply GKaiseril,


            I managed to realize the basic method. If I am right util.scand to convert, then get.time then calculate then util.printd?


            These Jouney Logs (timesheets) will definately not be longer than 24hours, as we are not doing long haul and have no relief crew.


            My thoughts were either using if start>end do one calc if not do another, or appending today's date and if start>end then tomorrows date to the end time. This is where I started to get stuck.


            I don't know much Javascript and couldn't find much specifically on adobe javascript, in the way of tutorials. I could try looking up how to do the script in Javascrip but I am not sure where the crossover is with the adobe specific functions is and so am just a bit lost of where to look next to write some code.


            Any guide as to this crossover would be appreciated, hopefully then I can learn to do it and write some code for these various bits.


            Thanks for your help, Keith