@qite/tide-booking-component 1.1.3 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/build-cjs/booking-product/components/multi-range-filter.d.ts +12 -0
- package/build/build-cjs/booking-wizard/features/booking/api.d.ts +4 -1
- package/build/build-cjs/booking-wizard/features/booking/booking-slice.d.ts +7 -3
- package/build/build-cjs/booking-wizard/features/booking/selectors.d.ts +23 -17
- package/build/build-cjs/booking-wizard/features/flight-options/flight-filter.d.ts +9 -0
- package/build/build-cjs/booking-wizard/features/flight-options/flight-option-flight.d.ts +8 -0
- package/build/build-cjs/booking-wizard/features/flight-options/flight-option-modal.d.ts +3 -0
- package/build/build-cjs/booking-wizard/features/flight-options/flight-option.d.ts +4 -9
- package/build/build-cjs/booking-wizard/features/flight-options/flight-utils.d.ts +6 -0
- package/build/build-cjs/booking-wizard/features/room-options/room-utils.d.ts +9 -0
- package/build/build-cjs/booking-wizard/features/room-options/room.d.ts +12 -0
- package/build/build-cjs/booking-wizard/features/room-options/traveler-rooms.d.ts +9 -0
- package/build/build-cjs/booking-wizard/types.d.ts +101 -0
- package/build/build-cjs/index.js +1563 -606
- package/build/build-cjs/shared/utils/localization-util.d.ts +30 -2
- package/build/build-esm/booking-product/components/multi-range-filter.d.ts +12 -0
- package/build/build-esm/booking-wizard/features/booking/api.d.ts +4 -1
- package/build/build-esm/booking-wizard/features/booking/booking-slice.d.ts +7 -3
- package/build/build-esm/booking-wizard/features/booking/selectors.d.ts +23 -17
- package/build/build-esm/booking-wizard/features/flight-options/flight-filter.d.ts +9 -0
- package/build/build-esm/booking-wizard/features/flight-options/flight-option-flight.d.ts +8 -0
- package/build/build-esm/booking-wizard/features/flight-options/flight-option-modal.d.ts +3 -0
- package/build/build-esm/booking-wizard/features/flight-options/flight-option.d.ts +4 -9
- package/build/build-esm/booking-wizard/features/flight-options/flight-utils.d.ts +6 -0
- package/build/build-esm/booking-wizard/features/room-options/room-utils.d.ts +9 -0
- package/build/build-esm/booking-wizard/features/room-options/room.d.ts +12 -0
- package/build/build-esm/booking-wizard/features/room-options/traveler-rooms.d.ts +9 -0
- package/build/build-esm/booking-wizard/types.d.ts +101 -0
- package/build/build-esm/index.js +1564 -607
- package/build/build-esm/shared/utils/localization-util.d.ts +30 -2
- package/package.json +3 -3
- package/rollup.config.js +23 -23
- package/src/booking-product/components/multi-range-filter.css +115 -0
- package/src/booking-product/components/multi-range-filter.tsx +114 -0
- package/src/booking-wizard/components/labeled-input.tsx +64 -64
- package/src/booking-wizard/components/labeled-select.tsx +69 -69
- package/src/booking-wizard/components/step-indicator.tsx +3 -3
- package/src/booking-wizard/features/booking/api.ts +12 -1
- package/src/booking-wizard/features/booking/booking-self-contained.tsx +50 -20
- package/src/booking-wizard/features/booking/booking-slice.ts +45 -9
- package/src/booking-wizard/features/booking/booking.tsx +67 -56
- package/src/booking-wizard/features/booking/selectors.ts +38 -11
- package/src/booking-wizard/features/flight-options/flight-filter.tsx +343 -0
- package/src/booking-wizard/features/flight-options/flight-option-flight.tsx +350 -0
- package/src/booking-wizard/features/flight-options/flight-option.tsx +30 -759
- package/src/booking-wizard/features/flight-options/flight-utils.ts +401 -0
- package/src/booking-wizard/features/flight-options/index.tsx +55 -368
- package/src/booking-wizard/features/price-details/util.ts +6 -6
- package/src/booking-wizard/features/product-options/option-room.tsx +3 -5
- package/src/booking-wizard/features/product-options/options-form.tsx +46 -54
- package/src/booking-wizard/features/room-options/index.tsx +48 -144
- package/src/booking-wizard/features/room-options/room-utils.ts +143 -0
- package/src/booking-wizard/features/room-options/room.tsx +124 -0
- package/src/booking-wizard/features/room-options/traveler-rooms.tsx +63 -0
- package/src/booking-wizard/features/sidebar/sidebar-util.ts +2 -2
- package/src/booking-wizard/features/summary/summary.tsx +2 -2
- package/src/booking-wizard/features/travelers-form/travelers-form.tsx +1 -1
- package/src/booking-wizard/types.ts +116 -0
- package/src/shared/components/rating.tsx +21 -21
- package/src/shared/translations/fr-BE.json +222 -192
- package/src/shared/translations/nl-BE.json +222 -192
- package/src/shared/utils/class-util.ts +9 -9
- package/tsconfig.json +24 -24
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import { BookingPackageFlight, BookingPackageFlightMetaDataLine } from "@qite/tide-client/build/types";
|
|
2
|
+
import { differenceInMinutes, isEqual, parseISO } from "date-fns";
|
|
3
|
+
import { FlightDirectionFilter, FlightFilterOption, FlightFilterOptions, GroupedFlightDetails, GroupedFlights } from "../../types";
|
|
4
|
+
|
|
5
|
+
/*interface FlightGroup {
|
|
6
|
+
code: string;
|
|
7
|
+
startDate: Date,
|
|
8
|
+
endDate: Date;
|
|
9
|
+
options: BookingPackageFlight[];
|
|
10
|
+
}*/
|
|
11
|
+
|
|
12
|
+
export const buildGroupedFlights = (outwardFlights: BookingPackageFlight[] | undefined, returnFlights: BookingPackageFlight[] | undefined) => {
|
|
13
|
+
if (!outwardFlights || !returnFlights) return [] as GroupedFlights[];
|
|
14
|
+
|
|
15
|
+
// let outwardGroups = groupFlights(outwardFlights);
|
|
16
|
+
// let returnGroups = groupFlights(returnFlights);
|
|
17
|
+
|
|
18
|
+
const pairs: { outward: BookingPackageFlight, return: BookingPackageFlight }[] = [];
|
|
19
|
+
outwardFlights.forEach(outwardFlight => {
|
|
20
|
+
if (outwardFlight.externalGuid) {
|
|
21
|
+
const returnFlight = returnFlights.find(x => x.externalGuid === outwardFlight.externalGuid)!;
|
|
22
|
+
pairs.push({ outward: outwardFlight, return: returnFlight });
|
|
23
|
+
} else {
|
|
24
|
+
const outwardCode = outwardFlight.code.substring(0, 7);
|
|
25
|
+
const returnCode = outwardCode.split(" ").reduce((a, b) => `${b} ${a}`);
|
|
26
|
+
|
|
27
|
+
returnFlights.filter(x => x.code.startsWith(returnCode)).forEach(returnFlight => {
|
|
28
|
+
pairs.push({ outward: outwardFlight, return: returnFlight });
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const results = pairs.map(x => {
|
|
34
|
+
const outwardFlightDetails = getFlightDetails(x.outward);
|
|
35
|
+
const returnFlightDetails = getFlightDetails(x.return);
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
isSelected: x.outward.isSelected && x.return.isSelected,
|
|
39
|
+
price: x.outward.price + x.return.price,
|
|
40
|
+
outward: outwardFlightDetails,
|
|
41
|
+
return: returnFlightDetails,
|
|
42
|
+
selectedOutward: x.outward,
|
|
43
|
+
selectedReturn: x.return
|
|
44
|
+
} as GroupedFlights;
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return results;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const buildFilterOptions = (
|
|
51
|
+
outwardFlights: BookingPackageFlight[] | undefined,
|
|
52
|
+
returnFlights: BookingPackageFlight[] | undefined,
|
|
53
|
+
translations: any
|
|
54
|
+
) => {
|
|
55
|
+
if (!outwardFlights || !returnFlights) return undefined;
|
|
56
|
+
|
|
57
|
+
const airports: FlightFilterOption[] = [];
|
|
58
|
+
const airlines: FlightFilterOption[] = [];
|
|
59
|
+
const numberOfStops: FlightFilterOption[] = [];
|
|
60
|
+
const outwardDeparturePeriods: FlightFilterOption[] = [];
|
|
61
|
+
const returnDeparturePeriods: FlightFilterOption[] = [];
|
|
62
|
+
|
|
63
|
+
let lowestDepartureTravelDuration = 9999;
|
|
64
|
+
let highestDepartureTravelDuration = 0
|
|
65
|
+
let lowestDepartureChangeDuration = 9999;
|
|
66
|
+
let highestDepartureChangeDuration = 0;
|
|
67
|
+
|
|
68
|
+
outwardFlights.forEach(flight => {
|
|
69
|
+
const airlineCode = flight.code.split('/')[1];
|
|
70
|
+
|
|
71
|
+
if (flight.flightMetaData.flightLines?.length) {
|
|
72
|
+
const firstLine = flight.flightMetaData.flightLines[0];
|
|
73
|
+
|
|
74
|
+
if (!airports.some(x => x.value === firstLine.departureAirport)) {
|
|
75
|
+
airports.push({
|
|
76
|
+
value: firstLine?.departureAirport,
|
|
77
|
+
label: firstLine.departureAirportDescription,
|
|
78
|
+
count: 0,
|
|
79
|
+
isSelected: false
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (!airlines.some(x => x.value === airlineCode)) {
|
|
85
|
+
airlines.push({
|
|
86
|
+
value: airlineCode,
|
|
87
|
+
label: flight.airlineDescription,
|
|
88
|
+
count: 0,
|
|
89
|
+
isSelected: false
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const stopCount = flight.flightMetaData.flightLines.length - 1;
|
|
94
|
+
if (!numberOfStops.some(x => x.value === (stopCount + ''))) {
|
|
95
|
+
numberOfStops.push({
|
|
96
|
+
value: (stopCount + ''),
|
|
97
|
+
label: stopCount === 0
|
|
98
|
+
? translations.FLIGHTS_FORM.DIRECT_FLIGHT
|
|
99
|
+
: stopCount == 1
|
|
100
|
+
? `${stopCount} ${translations.FLIGHTS_FORM.STOP}`
|
|
101
|
+
: `${stopCount} ${translations.FLIGHTS_FORM.STOPS}`,
|
|
102
|
+
count: 0,
|
|
103
|
+
isSelected: false
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const departureTime = flight.flightMetaData.flightLines[0].departureTime;
|
|
108
|
+
const timeBracket = determineTimeBracket(departureTime);
|
|
109
|
+
if (!outwardDeparturePeriods.some(x => x.value === timeBracket)) {
|
|
110
|
+
outwardDeparturePeriods.push({
|
|
111
|
+
value: timeBracket,
|
|
112
|
+
label: getBracketTranslation(timeBracket, translations),
|
|
113
|
+
count: 0,
|
|
114
|
+
isSelected: false
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const travelDurationInMinutes = minutesFromTicks(flight.flightMetaData.durationInTicks);
|
|
119
|
+
if (travelDurationInMinutes > highestDepartureTravelDuration) highestDepartureTravelDuration = travelDurationInMinutes;
|
|
120
|
+
if (travelDurationInMinutes < lowestDepartureTravelDuration) lowestDepartureTravelDuration = travelDurationInMinutes;
|
|
121
|
+
|
|
122
|
+
const changeDurationInMinutes = getTotalChangeDuration(flight);
|
|
123
|
+
if (changeDurationInMinutes > highestDepartureChangeDuration) highestDepartureChangeDuration = changeDurationInMinutes;
|
|
124
|
+
if (changeDurationInMinutes < lowestDepartureChangeDuration) lowestDepartureChangeDuration = changeDurationInMinutes;
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
let lowestReturnTravelDuration = 9999;
|
|
128
|
+
let highestReturnTravelDuration = 0
|
|
129
|
+
let lowestReturnChangeDuration = 9999;
|
|
130
|
+
let highestReturnChangeDuration = 0;
|
|
131
|
+
|
|
132
|
+
returnFlights.forEach(flight => {
|
|
133
|
+
const durationInMinutes = minutesFromTicks(flight.flightMetaData.durationInTicks);
|
|
134
|
+
if (durationInMinutes > highestReturnTravelDuration) highestReturnTravelDuration = durationInMinutes;
|
|
135
|
+
if (durationInMinutes < lowestReturnTravelDuration) lowestReturnTravelDuration = durationInMinutes;
|
|
136
|
+
|
|
137
|
+
const changeDurationInMinutes = getTotalChangeDuration(flight);
|
|
138
|
+
if (changeDurationInMinutes > highestReturnChangeDuration) highestReturnChangeDuration = changeDurationInMinutes;
|
|
139
|
+
if (changeDurationInMinutes < lowestReturnChangeDuration) lowestReturnChangeDuration = changeDurationInMinutes;
|
|
140
|
+
|
|
141
|
+
const departureTime = flight.flightMetaData.flightLines[0].departureTime;
|
|
142
|
+
const timeBracket = determineTimeBracket(departureTime);
|
|
143
|
+
if (!returnDeparturePeriods.some(x => x.value === timeBracket)) {
|
|
144
|
+
returnDeparturePeriods.push({
|
|
145
|
+
value: timeBracket,
|
|
146
|
+
label: getBracketTranslation(timeBracket, translations),
|
|
147
|
+
count: 0,
|
|
148
|
+
isSelected: false
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
airports: airports,
|
|
155
|
+
airlines: airlines,
|
|
156
|
+
numberOfStops: numberOfStops,
|
|
157
|
+
outward: {
|
|
158
|
+
departurePeriod: outwardDeparturePeriods,
|
|
159
|
+
travelDuration: {
|
|
160
|
+
min: lowestDepartureTravelDuration,
|
|
161
|
+
max: highestDepartureTravelDuration,
|
|
162
|
+
selectedMin: lowestDepartureTravelDuration,
|
|
163
|
+
selectedMax: highestDepartureTravelDuration
|
|
164
|
+
},
|
|
165
|
+
changeDuration: {
|
|
166
|
+
min: lowestDepartureChangeDuration,
|
|
167
|
+
max: highestDepartureChangeDuration,
|
|
168
|
+
selectedMin: lowestDepartureChangeDuration,
|
|
169
|
+
selectedMax: highestDepartureChangeDuration
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
return: {
|
|
173
|
+
departurePeriod: returnDeparturePeriods,
|
|
174
|
+
travelDuration: {
|
|
175
|
+
min: lowestReturnTravelDuration,
|
|
176
|
+
max: highestReturnTravelDuration,
|
|
177
|
+
selectedMin: lowestReturnTravelDuration,
|
|
178
|
+
selectedMax: highestReturnTravelDuration
|
|
179
|
+
},
|
|
180
|
+
changeDuration: {
|
|
181
|
+
min: lowestReturnChangeDuration,
|
|
182
|
+
max: highestReturnChangeDuration,
|
|
183
|
+
selectedMin: lowestReturnChangeDuration,
|
|
184
|
+
selectedMax: highestReturnChangeDuration
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
} as FlightFilterOptions;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export const filterGroupedFlights = (groups: GroupedFlights[], filterOptions: FlightFilterOptions | undefined) => {
|
|
191
|
+
if (!groups.length || !filterOptions) return [];
|
|
192
|
+
|
|
193
|
+
let filteredGroups = groups;
|
|
194
|
+
if (filterOptions.airlines.some(x => x.isSelected)) {
|
|
195
|
+
const selectedAirlineCodes = filterOptions.airlines.filter(x => x.isSelected);
|
|
196
|
+
filteredGroups = filteredGroups.filter(x => selectedAirlineCodes.some(y => y.value === x.outward.airlineCode));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (filterOptions.airports.some(x => x.isSelected)) {
|
|
200
|
+
const selectedAirlineCodes = filterOptions.airports.filter(x => x.isSelected);
|
|
201
|
+
filteredGroups = filteredGroups.filter(x => selectedAirlineCodes.some(y => y.value === x.outward.departureAirportCode));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (filterOptions.numberOfStops.some(x => x.isSelected)) {
|
|
205
|
+
const selectedNumberOfStops = filterOptions.airlines.filter(x => x.isSelected);
|
|
206
|
+
filteredGroups = filteredGroups.filter(x => selectedNumberOfStops.some(y => parseInt(y.value) === (x.outward.flightLines.length - 1)));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
filteredGroups = filterGroupedFlightByDirection(filteredGroups, true, filterOptions.outward);
|
|
210
|
+
filteredGroups = filterGroupedFlightByDirection(filteredGroups, false, filterOptions.return);
|
|
211
|
+
|
|
212
|
+
return filteredGroups;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const filterGroupedFlightByDirection = (groups: GroupedFlights[], isOutward: boolean, directionFilter: FlightDirectionFilter) => {
|
|
216
|
+
let filteredGroups = groups;
|
|
217
|
+
|
|
218
|
+
if (directionFilter.departurePeriod.some(x => x.isSelected)) {
|
|
219
|
+
const selectedDeparturePeriods = directionFilter.departurePeriod.filter(x => x.isSelected);
|
|
220
|
+
filteredGroups = filteredGroups.filter(x => selectedDeparturePeriods.some(y => y.value === determineTimeBracket((isOutward ? x.outward : x.return).departureTime)));
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
filteredGroups = filteredGroups.filter(x => directionFilter.travelDuration.selectedMin <= (isOutward ? x.outward : x.return).travelDurationMinutes && (isOutward ? x.outward : x.return).travelDurationMinutes <= directionFilter.travelDuration.selectedMax);
|
|
224
|
+
return filteredGroups.filter(x => directionFilter.changeDuration.selectedMin <= (isOutward ? x.outward : x.return).changeDurationMinutes && (isOutward ? x.outward : x.return).changeDurationMinutes <= directionFilter.changeDuration.selectedMax);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export const formatMinutes = (minutes: number) => {
|
|
228
|
+
var hh = Math.floor(minutes / 60);
|
|
229
|
+
var mm = Math.floor(minutes % 60);
|
|
230
|
+
return pad(hh, 2) + ":" + pad(mm, 2);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const getFlightDetails = (flight: BookingPackageFlight) => {
|
|
234
|
+
const firstLine = flight.flightMetaData.flightLines[0];
|
|
235
|
+
const lastLine = flight.flightMetaData.flightLines[flight.flightMetaData.flightLines.length - 1];
|
|
236
|
+
|
|
237
|
+
const airlineCode = flight.code.split('/')[1];
|
|
238
|
+
const waitDurations = getWaitDurations(flight.flightMetaData.flightLines);
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
airline: flight.airlineDescription,
|
|
242
|
+
airlineCode: airlineCode,
|
|
243
|
+
departureDate: firstLine.departureDate,
|
|
244
|
+
departureTime: firstLine.departureTime,
|
|
245
|
+
departureAirportCode: firstLine.departureAirport,
|
|
246
|
+
departureAirport: firstLine.departureAirportDescription,
|
|
247
|
+
arrivalDate: lastLine.arrivalDate,
|
|
248
|
+
arrivalTime: lastLine.arrivalTime,
|
|
249
|
+
arrivalAirport: lastLine.arrivalAirportDescription,
|
|
250
|
+
travelDuration: formatDuration(flight.flightMetaData.durationInTicks),
|
|
251
|
+
travelDurationMinutes: minutesFromTicks(flight.flightMetaData.durationInTicks),
|
|
252
|
+
changeDurationMinutes: getTotalChangeDuration(flight),
|
|
253
|
+
numberOfStops: flight.flightMetaData.flightLines.length - 1,
|
|
254
|
+
isNextDay: isNextDay(firstLine.departureDate, lastLine.arrivalDate),
|
|
255
|
+
travelClass: firstLine.travelClass,
|
|
256
|
+
flightLines: flight.flightMetaData.flightLines.map((x, i) => ({
|
|
257
|
+
airline: x.operatingAirlineDescription,
|
|
258
|
+
departureDate: x.departureDate,
|
|
259
|
+
departureTime: x.departureTime,
|
|
260
|
+
departureAirport: x.departureAirportDescription,
|
|
261
|
+
arrivalDate: x.arrivalDate,
|
|
262
|
+
arrivalTime: x.arrivalTime,
|
|
263
|
+
arrivalAirport: x.arrivalAirportDescription,
|
|
264
|
+
number: `${x.airlineCode} ${x.number}`,
|
|
265
|
+
travelDuration: formatDuration(x.durationInTicks),
|
|
266
|
+
waitDuration: waitDurations.length - 1 <= i ? waitDurations[i] : undefined,
|
|
267
|
+
}))
|
|
268
|
+
} as GroupedFlightDetails;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const isNextDay = (startDateString: string, endDateString: string) => {
|
|
272
|
+
const startDate = parseISO(startDateString);
|
|
273
|
+
const endDate = parseISO(endDateString);
|
|
274
|
+
|
|
275
|
+
return !isEqual(startDate, endDate);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const getWaitDurations = (lines: BookingPackageFlightMetaDataLine[]) => {
|
|
279
|
+
if (lines.length <= 1) return [];
|
|
280
|
+
let arrivalDate = lines[0].arrivalDate;
|
|
281
|
+
let arrivalTime = lines[0].arrivalTime;
|
|
282
|
+
|
|
283
|
+
const waitDurations: string[] = [];
|
|
284
|
+
for (var i = 1; i < lines.length; i++) {
|
|
285
|
+
const line = lines[i];
|
|
286
|
+
|
|
287
|
+
const waitDuration = getWaitDuration(arrivalDate, arrivalTime, line.departureDate, line.departureTime);
|
|
288
|
+
waitDurations.push(waitDuration);
|
|
289
|
+
|
|
290
|
+
arrivalDate = line.arrivalDate;
|
|
291
|
+
arrivalTime = line.arrivalTime;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return waitDurations;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const getWaitDuration = (arrivalDateString: string, arrivalTime: string, departureDateString: string, departureTime: string) => {
|
|
298
|
+
const minutes = getWaitDurationInMinutes(arrivalDateString, arrivalTime, departureDateString, departureTime);
|
|
299
|
+
|
|
300
|
+
var hh = Math.floor(minutes / 60);
|
|
301
|
+
var mm = Math.floor(minutes % 60);
|
|
302
|
+
return pad(hh, 2) + ":" + pad(mm, 2);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const getWaitDurationInMinutes = (arrivalDateString: string, arrivalTime: string, departureDateString: string, departureTime: string) => {
|
|
306
|
+
const arrivalDate = parseISO(arrivalDateString);
|
|
307
|
+
const arrivalTimeParts = arrivalTime.split(':');
|
|
308
|
+
|
|
309
|
+
arrivalDate.setHours(parseInt(arrivalTimeParts[0]));
|
|
310
|
+
arrivalDate.setMinutes(parseInt(arrivalTimeParts[1]));
|
|
311
|
+
|
|
312
|
+
const departureDate = parseISO(departureDateString);
|
|
313
|
+
const departureTimeParts = departureTime.split(':');
|
|
314
|
+
|
|
315
|
+
departureDate.setHours(parseInt(departureTimeParts[0]));
|
|
316
|
+
departureDate.setMinutes(parseInt(departureTimeParts[1]));
|
|
317
|
+
|
|
318
|
+
return differenceInMinutes(departureDate, arrivalDate);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/*const groupFlights = (flights: BookingPackageFlight[]) => {
|
|
322
|
+
let flightsPool = [...flights];
|
|
323
|
+
let groups = [] as FlightGroup[];
|
|
324
|
+
for (var i = 0; i < flightsPool.length; i++) {
|
|
325
|
+
const flight = flightsPool[i];
|
|
326
|
+
|
|
327
|
+
const relatedFlights = flightsPool.filter(x => x != flight
|
|
328
|
+
&& x.code === flight.code
|
|
329
|
+
&& isDateEqual(x.startDateTime, flight.startDateTime)
|
|
330
|
+
&& isDateEqual(x.endDateTime, flight.endDateTime)
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
flightsPool = flightsPool.filter(x => x != flight
|
|
334
|
+
&& relatedFlights.some(y => y != x));
|
|
335
|
+
|
|
336
|
+
groups.push({
|
|
337
|
+
code: flight.code,
|
|
338
|
+
startDate: parseISO(flight.startDateTime),
|
|
339
|
+
endDate: parseISO(flight.endDateTime),
|
|
340
|
+
options: [flight, ...relatedFlights]
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const isDateEqual = (first: string, second: string) => {
|
|
346
|
+
const firstDate = parseISO(first);
|
|
347
|
+
const secondDate = parseISO(second);
|
|
348
|
+
|
|
349
|
+
return isEqual(firstDate, secondDate);
|
|
350
|
+
}*/
|
|
351
|
+
|
|
352
|
+
const minutesFromTicks = (ticks: number) => {
|
|
353
|
+
const totalSeconds = ticks / 10_000_000;
|
|
354
|
+
return Math.floor(totalSeconds / 60);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
const formatDuration = (ticks: number) => {
|
|
358
|
+
if (!ticks) return '';
|
|
359
|
+
|
|
360
|
+
const totalSeconds = ticks / 10_000_000;
|
|
361
|
+
var hh = Math.floor(totalSeconds / 3600);
|
|
362
|
+
var mm = Math.floor((totalSeconds % 3600) / 60);
|
|
363
|
+
return pad(hh, 2) + ":" + pad(mm, 2);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const pad = (input: number, width: number) => {
|
|
367
|
+
const n = input + '';
|
|
368
|
+
return n.length >= width ? n : new Array(width - n.length + 1).join('0') + n;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const determineTimeBracket = (input: string) => {
|
|
372
|
+
const time = parseInt(input.replace(':', ''));
|
|
373
|
+
if (time <= 500) return '0000-0500';
|
|
374
|
+
if (time > 500 && time <= 1200) return '0500-1200';
|
|
375
|
+
if (time > 1200 && time <= 1800) return '1201-1800';
|
|
376
|
+
return '1800-2400';
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const getBracketTranslation = (input: string, translations: any) => {
|
|
380
|
+
if (input === '0000-0500') return translations.FLIGHTS_FORM.NIGHT_DEPARTURE;
|
|
381
|
+
if (input === '0500-1200') return translations.FLIGHTS_FORM.MORNING_DEPARTURE;
|
|
382
|
+
if (input === '1200-1800') return translations.FLIGHTS_FORM.AFTERNOON_DEPARTURE;
|
|
383
|
+
return translations.FLIGHTS_FORM.EVENING_DEPARTURE;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
const getTotalChangeDuration = (flight: BookingPackageFlight) => {
|
|
387
|
+
const lines = flight.flightMetaData.flightLines;
|
|
388
|
+
|
|
389
|
+
if (lines.length <= 1) return 0;
|
|
390
|
+
let arrivalDate = lines[0].arrivalDate;
|
|
391
|
+
let arrivalTime = lines[0].arrivalTime;
|
|
392
|
+
|
|
393
|
+
let waitDuration = 0;
|
|
394
|
+
for (var i = 1; i < lines.length; i++) {
|
|
395
|
+
const line = lines[i];
|
|
396
|
+
|
|
397
|
+
waitDuration += getWaitDurationInMinutes(arrivalDate, arrivalTime, line.departureDate, line.departureTime);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
return waitDuration;
|
|
401
|
+
}
|