%other procedures
%==================================================================

%caculate the waiting time between two flights
%If we can not catch nextflight in same day
%we will wait flight on nextday
waiting(Arrive, Departure, Wait):-
convert(Arrive, NewArrive),
NewArrive + 1 =< Departure,
Wait is Departure - NewArrive,
!.

waiting(Arrive, Departure, Wait):-
Wait is Departure + 24 - Arrive.

%negation of cancelled flight
notcancel(Flight):-
cancelled(Flight),
!,
fail.
notcancel(Flight):-
Flight = Flight.

%airport-closed case
%return true when Time is between airport close time
notclose(City, Time):-
airport_closed(City, Begin, End),
convert(Time, NewTime),
is_between(NewTime, Begin, End),
!,
fail.
notclose(City, Time):-
City = City,
Time = Time.


%convert Time to 24 hour clock
convert(Time, NewTime):-
Time < 24,
NewTime = Time,
!.
convert(Time, NewTime):-
NewTime is Time - 24.

%return true when Flight is between Begin and End
%Begin and End are in same day
is_between(Flight, Begin, End):-
Begin < End,
Flight >= Begin,
Flight < End.
%End is on the next day of Begin
is_between(Flight, Begin, End):-
Begin > End,
Flight >= Begin.
is_between(Flight, Begin, End):-
Begin > End,
Flight < End.


%rescheduled case
%check whether the flight is rescheduled
notchange(FlightNr):-
rescheduled(FlightNr, _, _),
!,
fail.
notchange(FlightNr):-
FlightNr = FlightNr.