These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Time Subtraction

cramia
Registered: Oct 6 2008
Posts: 33

Hello All,

I need a javascript to perform the following calculation:

Take an aicraft's Actual time of Departure (ATD) and subtract it from the Scheduled Departure Time (SDT) to display the Actual Delay in minutes.

For example:
Flight TA570 SDT 23:50 (time entered manually)
Actual Departure Time 00:22 (time entered manually)
Delay = 32 minutes (calculated by the script)

I know it's a simple task...but I am new using this thing and subtraction is not among the built-in Acrobat calculations.

Thanks for your time and help!!

CRamia

CRamia
New York

My Product Information:
Acrobat Pro 8.0, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Start here: http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/date_time_part1/

Date/time calculations can get tricky, particularly when validating inputs and when assumptions are made. For example, in the case above you're assuming a delay of less than 24 hours. A field value of "1:2" will get displayed as "01:02" for a text field set up with a Time format category that uses the HH:MM format string.

George
cramia
Registered: Oct 6 2008
Posts: 33
The delay is always less than 24 hours...it could be afew minutes or a few hours...always less than 24 hours.

A flight that is delayed for the next day get a new number.



CRamia

CRamia
New York

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Have you looked at all the parts of the series. [url=http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/date_time_part3/index.php|Working with date and time in Acrobat JavaScript Part 3]has an extensive example of time calculation in Acro Forms. If you are using LiveCycle Designer you can use the "Time2Num()" function. And as shown in the Acro Forms JavaScript getting the format of the date/time string to process as a parameter for the date/time functions is very important to get the correct result.

You also may need to adjust for dates if there is a difference in the dates for the times for the flight since flights can last over 12 hours or the delays could be more than 24 hours. For example, flying from Thahiti to Boston, I was held in Tahiti for a full day and there were long delays in Los Angeles and Philiadelphia while Logan Ariport was closed for 24 hours because of a snow storm.

For LiveCycle Desinger assuming the start and end times are within the same day, the following script will compute the difference in hours and minutes and format the display into hours and minutes using the format of 'h:MM A":

if( HasValue(EndTime) & HasValue(StartTime) ) then
// compute time difference in minutes
var TimeDiff = (Time2Num(EndTime.formattedValue, "h:MM A") - Time2Num(StartTime.formattedValue, "h:MM A")) / (1000 * 60)
// truncate to hours
var HourDiff = Floor(TimeDiff / 60)
// get minutes less than 60
var MinDiff = Mod(TimeDiff, 60)
// build fomatted dispaly string
Concat( Format("Z9", HourDiff), ":", Format("99",MinDiff) )
else
// if any values missing null the output
null
endif



Your example indicates a change in the dates for the date time of the starting and ending times, which should be provided for.

George Kaiser

cramia
Registered: Oct 6 2008
Posts: 33
gkaiseril wrote:
Have you looked at all the parts of the series. [url=http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/date_time_part3/index.php|Working with date and time in Acrobat JavaScript Part 3]has an extensive example of time calculation in Acro Forms. If you are using LiveCycle Designer you can use the "Time2Num()" function. And as shown in the Acro Forms JavaScript getting the format of the date/time string to process as a parameter for the date/time functions is very important to get the correct result.You also may need to adjust for dates if there is a difference in the dates for the times for the flight since flights can last over 12 hours or the delays could be more than 24 hours. For example, flying from Thahiti to Boston, I was held in Tahiti for a full day and there were long delays in Los Angeles and Philiadelphia while Logan Ariport was closed for 24 hours because of a snow storm.

For LiveCycle Desinger assuming the start and end times are within the same day, the following script will compute the difference in hours and minutes and format the display into hours and minutes using the format of 'h:MM A":

if( HasValue(EndTime) & HasValue(StartTime) ) then
// compute time difference in minutes
var TimeDiff = (Time2Num(EndTime.formattedValue, "h:MM A") - Time2Num(StartTime.formattedValue, "h:MM A")) / (1000 * 60)
// truncate to hours
var HourDiff = Floor(TimeDiff / 60)
// get minutes less than 60
var MinDiff = Mod(TimeDiff, 60)
// build fomatted dispaly string
Concat( Format("Z9", HourDiff), ":", Format("99",MinDiff) )
else
// if any values missing null the output
null
endif



Your example indicates a change in the dates for the date time of the starting and ending times, which should be provided for.
Your flight time was expanded...but the actual delay for the first take-off wasn't that long, and that's the time I base my reports on: it's called pushback time, which is the only one I deal with.

Thanks gkaiseril !!

CRamia

CRamia
New York