how to calculate transit time
digital230 opened this issue · 2 comments
digital230 commented
Hi,
is there any way to get transit time from api.. if not then how to calculate it. thanks
yeabsira-gashaw commented
[
{
from: 'ADD',
to: 'CAI',
group: 0,
departure: '2020-07-05T04:10:00.000+03:00',
arrival: '2020-07-05T06:40:00.000+02:00',
airline: 'MS',
flightNumber: '852',
uapi_segment_ref: '5US5sLPc1BKAhX5hTAAAAA==',
serviceClass: 'Business',
plane: [ '738' ],
duration: [ '210' ],
techStops: [],
bookingClass: 'J',
baggage: [ [Object] ],
fareBasisCode: 'JREETO'
},
{
from: 'CAI',
to: 'IAD',
group: 0,
departure: '2020-07-05T23:20:00.000+02:00',
arrival: '2020-07-06T05:10:00.000-04:00',
airline: 'MS',
flightNumber: '981',
uapi_segment_ref: '5US5sLPc1BKAjX5hTAAAAA==',
serviceClass: 'Business',
plane: [ '789' ],
duration: [ '710' ],
techStops: [],
bookingClass: 'J',
baggage: [ [Object] ],
fareBasisCode: 'JREETO'
}
]
As you can see from the above segments array ( you can get that from directions object ), it has 1 stop between ADD to CAI & CAI to WAS. So to calculate the transit time the passenger stays in CAI before leaving to WAS, you can use momentjs library.
You can use this :
const tripStopAt = moment(segment[0].arrival) _// Time the plane lands in CAI coming from ADD_
const tripContinueAt = moment(segment[1].departure) _// Time the plane departs CAI to WAS_
const duration = moment.duration(tripContinueAt.diff(tripStopAt));
const hours = duration.asHours();
Now, you have the number of hours ( Transit Time ). You can modify it as per your need.
Thank You,
Yeabsira Gashaw
digital230 commented
thank u very much i wll try it today.