I need to create a form that allows users to enter departure and arrival dates and times. The form needs to compute the total time spent traveling minus meal/break times. Because the time periods can start and end on different dates, I need to factor in the date in the calculations but I am not sure how. I have also been asked to round the solution to the nearest quarter hours.
Example: Departure1 = 7/17/09 10:45 am, Arrival1 = 7/17/09 1:30 pm, Meals/Breaks1 = 30 minutes, total travel time = 2:30 hours
I use the Standard version of Acrobat 9, but I am not sure how to use AcroForms and the JavaScript date object.
I have been reading everything I can locate on time calculations and I have looked at Thom Parker's tutorial series on Working with date and time in Acrobat JavaScript but I am still having problems.
Honestly I think I am more confused.
Please Help!
Entering both the time and date as one field in the correct format can be difficult. So assuming you have separate fields for the dates and times of departure and arrival makes life easier for the end user. So assuming you have the following fields in the following formats:
Departure Date
field: 'departure.date'
format 'm/DD/YY'
Departure Time
field: 'departure.time'
format 'h:MM tt'
Arrival Date
field: 'arrival.date'
format 'm/DD/YY'
Departure Time
field: 'arrival.time'
format 'h:MM tt'
First, one needs to convert the date string and the time string to minutes, the smallest time element needed for this task. For this we need to know the format of the date and time values and the date and time values. Since this task will be done more than once, we can create a custom function that will make a single string of the combined date and time values with a known format.
From this string value and format, one can compute the number of milliseconds format the Epoch date for this date and time. Again since this function will occur more than once and is useful for other date time calculations one can create a custom function to perform this calculation and return the results in minutes.
With the number of minutes from the Epoch date for the departure and arrival, one can compute the total travel time in minutes by subtracting the departure minutes from the arrival minutes.
You now need only subtract the meal time and convert the resulting minutes to hours and minutes and format the display string.
George Kaiser