@qite/tide-booking-component 1.2.5 → 1.3.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.
Files changed (141) hide show
  1. package/.vs/ProjectSettings.json +3 -3
  2. package/.vs/VSWorkspaceState.json +5 -5
  3. package/README.md +8 -8
  4. package/build/build-cjs/booking-wizard/components/print-offer-button.d.ts +17 -0
  5. package/build/build-cjs/booking-wizard/types.d.ts +7 -0
  6. package/build/build-cjs/booking-wizard/use-offer-printer.d.ts +13 -0
  7. package/build/build-cjs/index.js +223 -72
  8. package/build/build-cjs/shared/utils/localization-util.d.ts +5 -0
  9. package/build/build-cjs/shared/utils/tide-api-utils.d.ts +1 -0
  10. package/build/build-esm/booking-wizard/components/print-offer-button.d.ts +17 -0
  11. package/build/build-esm/booking-wizard/types.d.ts +7 -0
  12. package/build/build-esm/booking-wizard/use-offer-printer.d.ts +13 -0
  13. package/build/build-esm/index.js +224 -73
  14. package/build/build-esm/shared/utils/localization-util.d.ts +5 -0
  15. package/build/build-esm/shared/utils/tide-api-utils.d.ts +1 -0
  16. package/package.json +75 -75
  17. package/rollup.config.js +23 -23
  18. package/src/booking-product/components/age-select.tsx +35 -35
  19. package/src/booking-product/components/amount-input.tsx +78 -78
  20. package/src/booking-product/components/date-range-picker/calendar-day.tsx +58 -58
  21. package/src/booking-product/components/date-range-picker/calendar.tsx +178 -178
  22. package/src/booking-product/components/date-range-picker/index.tsx +196 -196
  23. package/src/booking-product/components/dates.tsx +136 -136
  24. package/src/booking-product/components/footer.tsx +69 -69
  25. package/src/booking-product/components/header.tsx +79 -79
  26. package/src/booking-product/components/icon.tsx +251 -251
  27. package/src/booking-product/components/product.tsx +314 -314
  28. package/src/booking-product/components/rating.tsx +21 -21
  29. package/src/booking-product/components/rooms.tsx +195 -195
  30. package/src/booking-product/index.tsx +30 -30
  31. package/src/booking-product/settings-context.ts +14 -14
  32. package/src/booking-product/types.ts +28 -28
  33. package/src/booking-product/utils/api.ts +25 -25
  34. package/src/booking-product/utils/price.ts +29 -29
  35. package/src/booking-wizard/api-settings-slice.ts +24 -24
  36. package/src/booking-wizard/components/icon.tsx +508 -508
  37. package/src/booking-wizard/components/labeled-input.tsx +64 -64
  38. package/src/booking-wizard/components/labeled-select.tsx +69 -69
  39. package/src/booking-wizard/components/message.tsx +34 -34
  40. package/src/booking-wizard/components/multi-range-filter.tsx +113 -113
  41. package/src/booking-wizard/components/print-offer-button.tsx +66 -0
  42. package/src/booking-wizard/components/product-card.tsx +37 -37
  43. package/src/booking-wizard/components/step-indicator.tsx +51 -51
  44. package/src/booking-wizard/components/step-route.tsx +27 -27
  45. package/src/booking-wizard/declarations.d.ts +4 -4
  46. package/src/booking-wizard/features/booking/api.ts +49 -49
  47. package/src/booking-wizard/features/booking/booking-self-contained.tsx +384 -384
  48. package/src/booking-wizard/features/booking/booking-slice.ts +662 -662
  49. package/src/booking-wizard/features/booking/booking.tsx +356 -356
  50. package/src/booking-wizard/features/booking/constants.ts +16 -16
  51. package/src/booking-wizard/features/booking/selectors.ts +441 -441
  52. package/src/booking-wizard/features/confirmation/confirmation.tsx +97 -97
  53. package/src/booking-wizard/features/error/error.tsx +78 -78
  54. package/src/booking-wizard/features/flight-options/flight-filter.tsx +432 -432
  55. package/src/booking-wizard/features/flight-options/flight-option-flight.tsx +385 -385
  56. package/src/booking-wizard/features/flight-options/flight-option-modal.tsx +229 -229
  57. package/src/booking-wizard/features/flight-options/flight-option.tsx +81 -81
  58. package/src/booking-wizard/features/flight-options/flight-utils.ts +516 -516
  59. package/src/booking-wizard/features/flight-options/index.tsx +196 -196
  60. package/src/booking-wizard/features/price-details/price-details-api.ts +24 -24
  61. package/src/booking-wizard/features/price-details/price-details-slice.ts +178 -178
  62. package/src/booking-wizard/features/price-details/util.ts +155 -155
  63. package/src/booking-wizard/features/product-options/no-options.tsx +21 -21
  64. package/src/booking-wizard/features/product-options/none-option.tsx +120 -120
  65. package/src/booking-wizard/features/product-options/option-booking-airline-group.tsx +64 -64
  66. package/src/booking-wizard/features/product-options/option-booking-group.tsx +216 -216
  67. package/src/booking-wizard/features/product-options/option-item.tsx +317 -317
  68. package/src/booking-wizard/features/product-options/option-pax-card.tsx +201 -201
  69. package/src/booking-wizard/features/product-options/option-pax-group.tsx +175 -175
  70. package/src/booking-wizard/features/product-options/option-room.tsx +321 -321
  71. package/src/booking-wizard/features/product-options/option-unit-group.tsx +198 -198
  72. package/src/booking-wizard/features/product-options/option-units-card.tsx +185 -185
  73. package/src/booking-wizard/features/product-options/options-form.tsx +563 -459
  74. package/src/booking-wizard/features/room-options/index.tsx +187 -187
  75. package/src/booking-wizard/features/room-options/room-utils.ts +190 -190
  76. package/src/booking-wizard/features/room-options/room.tsx +160 -160
  77. package/src/booking-wizard/features/room-options/traveler-rooms.tsx +75 -75
  78. package/src/booking-wizard/features/sidebar/index.tsx +76 -76
  79. package/src/booking-wizard/features/sidebar/sidebar-flight.tsx +68 -68
  80. package/src/booking-wizard/features/sidebar/sidebar-util.ts +177 -177
  81. package/src/booking-wizard/features/sidebar/sidebar.tsx +364 -364
  82. package/src/booking-wizard/features/summary/summary-booking-option-pax.tsx +25 -25
  83. package/src/booking-wizard/features/summary/summary-booking-option-unit.tsx +25 -25
  84. package/src/booking-wizard/features/summary/summary-flight.tsx +39 -39
  85. package/src/booking-wizard/features/summary/summary-per-booking-option-group.tsx +69 -69
  86. package/src/booking-wizard/features/summary/summary-per-pax-option-group.tsx +63 -63
  87. package/src/booking-wizard/features/summary/summary-per-unit-option-group.tsx +66 -66
  88. package/src/booking-wizard/features/summary/summary-slice.ts +28 -28
  89. package/src/booking-wizard/features/summary/summary.tsx +674 -674
  90. package/src/booking-wizard/features/travelers-form/travelers-form-slice.ts +164 -164
  91. package/src/booking-wizard/features/travelers-form/travelers-form.tsx +754 -754
  92. package/src/booking-wizard/features/travelers-form/type-ahead-input.tsx +101 -101
  93. package/src/booking-wizard/features/travelers-form/validate-form.ts +245 -245
  94. package/src/booking-wizard/index.tsx +36 -36
  95. package/src/booking-wizard/settings-context.ts +67 -60
  96. package/src/booking-wizard/store.ts +31 -31
  97. package/src/booking-wizard/types.ts +283 -276
  98. package/src/booking-wizard/use-offer-printer.ts +136 -0
  99. package/src/index.ts +4 -4
  100. package/src/shared/components/loader.tsx +16 -16
  101. package/src/shared/translations/en-GB.json +237 -232
  102. package/src/shared/translations/fr-BE.json +238 -233
  103. package/src/shared/translations/nl-BE.json +237 -232
  104. package/src/shared/types.ts +4 -4
  105. package/src/shared/utils/class-util.ts +9 -9
  106. package/src/shared/utils/localization-util.ts +62 -62
  107. package/src/shared/utils/query-string-util.ts +119 -119
  108. package/src/shared/utils/tide-api-utils.ts +36 -36
  109. package/styles/booking-product-variables.scss +394 -394
  110. package/styles/booking-product.scss +446 -446
  111. package/styles/booking-wizard-variables.scss +873 -871
  112. package/styles/booking-wizard.scss +59 -59
  113. package/styles/components/_animations.scss +39 -39
  114. package/styles/components/_base.scss +107 -107
  115. package/styles/components/_booking.scss +879 -879
  116. package/styles/components/_button.scss +238 -238
  117. package/styles/components/_checkbox.scss +219 -219
  118. package/styles/components/_cta.scss +208 -208
  119. package/styles/components/_date-list.scss +41 -41
  120. package/styles/components/_date-range-picker.scss +225 -225
  121. package/styles/components/_decrement-increment.scss +35 -35
  122. package/styles/components/_dropdown.scss +72 -72
  123. package/styles/components/_flight-option.scss +1429 -1429
  124. package/styles/components/_form.scss +1583 -1583
  125. package/styles/components/_info-message.scss +71 -71
  126. package/styles/components/_input.scss +25 -25
  127. package/styles/components/_list.scss +187 -187
  128. package/styles/components/_loader.scss +72 -72
  129. package/styles/components/_mixins.scss +550 -550
  130. package/styles/components/_placeholders.scss +166 -166
  131. package/styles/components/_pricing-summary.scss +155 -155
  132. package/styles/components/_qsm.scss +17 -17
  133. package/styles/components/_radiobutton.scss +170 -170
  134. package/styles/components/_select-wrapper.scss +80 -80
  135. package/styles/components/_spinner.scss +29 -29
  136. package/styles/components/_step-indicators.scss +168 -168
  137. package/styles/components/_table.scss +81 -81
  138. package/styles/components/_tree.scss +530 -530
  139. package/styles/components/_typeahead.scss +281 -281
  140. package/styles/components/_variables.scss +89 -89
  141. package/tsconfig.json +24 -24
@@ -1,516 +1,516 @@
1
- import {
2
- BookingPackageFlight,
3
- BookingPackageFlightMetaDataLine,
4
- } from "@qite/tide-client/build/types";
5
- import { differenceInMinutes, isEqual, parseISO } from "date-fns";
6
- import {
7
- FlightDirectionFilter,
8
- FlightFilterOption,
9
- FlightFilterOptions,
10
- GroupedFlightDetails,
11
- GroupedFlights,
12
- } from "../../types";
13
-
14
- /*interface FlightGroup {
15
- code: string;
16
- startDate: Date,
17
- endDate: Date;
18
- options: BookingPackageFlight[];
19
- }*/
20
-
21
- export const buildGroupedFlights = (
22
- outwardFlights: BookingPackageFlight[] | undefined,
23
- returnFlights: BookingPackageFlight[] | undefined
24
- ) => {
25
- if (!outwardFlights || !returnFlights) return [] as GroupedFlights[];
26
-
27
- // let outwardGroups = groupFlights(outwardFlights);
28
- // let returnGroups = groupFlights(returnFlights);
29
-
30
- const pairs: {
31
- outward: BookingPackageFlight;
32
- return: BookingPackageFlight;
33
- }[] = [];
34
- outwardFlights.forEach((outwardFlight) => {
35
- if (outwardFlight.externalGuid) {
36
- const returnFlight = returnFlights.find(
37
- (x) => x.externalGuid === outwardFlight.externalGuid
38
- )!;
39
- pairs.push({ outward: outwardFlight, return: returnFlight });
40
- } else {
41
- const outwardCode = outwardFlight.code.substring(0, 7);
42
- const returnCode = outwardCode.split(" ").reduce((a, b) => `${b} ${a}`);
43
-
44
- returnFlights
45
- .filter((x) => x.code.startsWith(returnCode))
46
- .forEach((returnFlight) => {
47
- pairs.push({ outward: outwardFlight, return: returnFlight });
48
- });
49
- }
50
- });
51
-
52
- const results = pairs.map((x) => {
53
- const outwardFlightDetails = getFlightDetails(x.outward);
54
- const returnFlightDetails = getFlightDetails(x.return);
55
-
56
- return {
57
- isSelected: x.outward.isSelected && x.return.isSelected,
58
- price: x.outward.price + x.return.price,
59
- outward: outwardFlightDetails,
60
- return: returnFlightDetails,
61
- selectedOutward: x.outward,
62
- selectedReturn: x.return,
63
- } as GroupedFlights;
64
- });
65
-
66
- return results;
67
- };
68
-
69
- export const buildFilterOptions = (
70
- outwardFlights: BookingPackageFlight[] | undefined,
71
- returnFlights: BookingPackageFlight[] | undefined,
72
- translations: any
73
- ) => {
74
- if (!outwardFlights || !returnFlights) return undefined;
75
-
76
- const airports: FlightFilterOption[] = [];
77
- const airlines: FlightFilterOption[] = [];
78
- const numberOfStops: FlightFilterOption[] = [];
79
- const outwardDeparturePeriods: FlightFilterOption[] = [];
80
- const returnDeparturePeriods: FlightFilterOption[] = [];
81
-
82
- let lowestDepartureTravelDuration = 9999;
83
- let highestDepartureTravelDuration = 0;
84
- let lowestDepartureChangeDuration = 9999;
85
- let highestDepartureChangeDuration = 0;
86
-
87
- outwardFlights.forEach((flight) => {
88
- const airlineCode = flight.code.split("/")[1];
89
-
90
- if (flight.flightMetaData.flightLines?.length) {
91
- const firstLine = flight.flightMetaData.flightLines[0];
92
-
93
- if (!airports.some((x) => x.value === firstLine.departureAirport)) {
94
- airports.push({
95
- value: firstLine?.departureAirport,
96
- label: firstLine.departureAirportDescription,
97
- count: 0,
98
- isSelected: false,
99
- });
100
- }
101
- }
102
-
103
- if (!airlines.some((x) => x.value === airlineCode)) {
104
- airlines.push({
105
- value: airlineCode,
106
- label: flight.airlineDescription,
107
- count: 0,
108
- isSelected: false,
109
- });
110
- }
111
-
112
- const stopCount = flight.flightMetaData.flightLines.length - 1;
113
- if (!numberOfStops.some((x) => x.value === stopCount + "")) {
114
- numberOfStops.push({
115
- value: stopCount + "",
116
- label:
117
- stopCount === 0
118
- ? translations.FLIGHTS_FORM.DIRECT_FLIGHT
119
- : stopCount == 1
120
- ? `${stopCount} ${translations.FLIGHTS_FORM.STOP}`
121
- : `${stopCount} ${translations.FLIGHTS_FORM.STOPS}`,
122
- count: 0,
123
- isSelected: false,
124
- });
125
- }
126
-
127
- const departureTime = flight.flightMetaData.flightLines[0].departureTime;
128
- const timeBracket = determineTimeBracket(departureTime);
129
- if (!outwardDeparturePeriods.some((x) => x.value === timeBracket)) {
130
- outwardDeparturePeriods.push({
131
- value: timeBracket,
132
- label: getBracketTranslation(timeBracket, translations),
133
- count: 0,
134
- isSelected: false,
135
- });
136
- }
137
-
138
- const travelDurationInMinutes = minutesFromTicks(
139
- flight.flightMetaData.durationInTicks
140
- );
141
- if (travelDurationInMinutes > highestDepartureTravelDuration)
142
- highestDepartureTravelDuration = travelDurationInMinutes;
143
- if (travelDurationInMinutes < lowestDepartureTravelDuration)
144
- lowestDepartureTravelDuration = travelDurationInMinutes;
145
-
146
- const changeDurationInMinutes = getTotalChangeDuration(flight);
147
- if (changeDurationInMinutes > highestDepartureChangeDuration)
148
- highestDepartureChangeDuration = changeDurationInMinutes;
149
- if (changeDurationInMinutes < lowestDepartureChangeDuration)
150
- lowestDepartureChangeDuration = changeDurationInMinutes;
151
- });
152
-
153
- let lowestReturnTravelDuration = 9999;
154
- let highestReturnTravelDuration = 0;
155
- let lowestReturnChangeDuration = 9999;
156
- let highestReturnChangeDuration = 0;
157
-
158
- returnFlights.forEach((flight) => {
159
- const durationInMinutes = minutesFromTicks(
160
- flight.flightMetaData.durationInTicks
161
- );
162
- if (durationInMinutes > highestReturnTravelDuration)
163
- highestReturnTravelDuration = durationInMinutes;
164
- if (durationInMinutes < lowestReturnTravelDuration)
165
- lowestReturnTravelDuration = durationInMinutes;
166
-
167
- const changeDurationInMinutes = getTotalChangeDuration(flight);
168
- if (changeDurationInMinutes > highestReturnChangeDuration)
169
- highestReturnChangeDuration = changeDurationInMinutes;
170
- if (changeDurationInMinutes < lowestReturnChangeDuration)
171
- lowestReturnChangeDuration = changeDurationInMinutes;
172
-
173
- const departureTime = flight.flightMetaData.flightLines[0].departureTime;
174
- const timeBracket = determineTimeBracket(departureTime);
175
- if (!returnDeparturePeriods.some((x) => x.value === timeBracket)) {
176
- returnDeparturePeriods.push({
177
- value: timeBracket,
178
- label: getBracketTranslation(timeBracket, translations),
179
- count: 0,
180
- isSelected: false,
181
- });
182
- }
183
- });
184
-
185
- return {
186
- airports: airports,
187
- airlines: airlines,
188
- numberOfStops: numberOfStops,
189
- outward: {
190
- departurePeriod: outwardDeparturePeriods,
191
- travelDuration: {
192
- min: lowestDepartureTravelDuration,
193
- max: highestDepartureTravelDuration,
194
- selectedMin: lowestDepartureTravelDuration,
195
- selectedMax: highestDepartureTravelDuration,
196
- },
197
- changeDuration: {
198
- min: lowestDepartureChangeDuration,
199
- max: highestDepartureChangeDuration,
200
- selectedMin: lowestDepartureChangeDuration,
201
- selectedMax: highestDepartureChangeDuration,
202
- },
203
- },
204
- return: {
205
- departurePeriod: returnDeparturePeriods,
206
- travelDuration: {
207
- min: lowestReturnTravelDuration,
208
- max: highestReturnTravelDuration,
209
- selectedMin: lowestReturnTravelDuration,
210
- selectedMax: highestReturnTravelDuration,
211
- },
212
- changeDuration: {
213
- min: lowestReturnChangeDuration,
214
- max: highestReturnChangeDuration,
215
- selectedMin: lowestReturnChangeDuration,
216
- selectedMax: highestReturnChangeDuration,
217
- },
218
- },
219
- } as FlightFilterOptions;
220
- };
221
-
222
- export const filterGroupedFlights = (
223
- groups: GroupedFlights[],
224
- filterOptions: FlightFilterOptions | undefined
225
- ) => {
226
- if (!groups.length || !filterOptions) return [];
227
-
228
- let filteredGroups = groups;
229
- if (filterOptions.airlines.some((x) => x.isSelected)) {
230
- const selectedAirlineCodes = filterOptions.airlines.filter(
231
- (x) => x.isSelected
232
- );
233
- filteredGroups = filteredGroups.filter((x) =>
234
- selectedAirlineCodes.some((y) => y.value === x.outward.airlineCode)
235
- );
236
- }
237
-
238
- if (filterOptions.airports.some((x) => x.isSelected)) {
239
- const selectedAirlineCodes = filterOptions.airports.filter(
240
- (x) => x.isSelected
241
- );
242
- filteredGroups = filteredGroups.filter((x) =>
243
- selectedAirlineCodes.some(
244
- (y) => y.value === x.outward.departureAirportCode
245
- )
246
- );
247
- }
248
-
249
- if (filterOptions.numberOfStops.some((x) => x.isSelected)) {
250
- const selectedNumberOfStops = filterOptions.numberOfStops.filter(
251
- (x) => x.isSelected
252
- );
253
- filteredGroups = filteredGroups.filter((x) =>
254
- selectedNumberOfStops.some(
255
- (y) => parseInt(y.value) === x.outward.flightLines.length - 1
256
- )
257
- );
258
- }
259
-
260
- filteredGroups = filterGroupedFlightByDirection(
261
- filteredGroups,
262
- true,
263
- filterOptions.outward
264
- );
265
- filteredGroups = filterGroupedFlightByDirection(
266
- filteredGroups,
267
- false,
268
- filterOptions.return
269
- );
270
-
271
- return filteredGroups;
272
- };
273
-
274
- const filterGroupedFlightByDirection = (
275
- groups: GroupedFlights[],
276
- isOutward: boolean,
277
- directionFilter: FlightDirectionFilter
278
- ) => {
279
- let filteredGroups = groups;
280
-
281
- if (directionFilter.departurePeriod.some((x) => x.isSelected)) {
282
- const selectedDeparturePeriods = directionFilter.departurePeriod.filter(
283
- (x) => x.isSelected
284
- );
285
- filteredGroups = filteredGroups.filter((x) =>
286
- selectedDeparturePeriods.some(
287
- (y) =>
288
- y.value ===
289
- determineTimeBracket((isOutward ? x.outward : x.return).departureTime)
290
- )
291
- );
292
- }
293
-
294
- filteredGroups = filteredGroups.filter(
295
- (x) =>
296
- directionFilter.travelDuration.selectedMin <=
297
- (isOutward ? x.outward : x.return).travelDurationMinutes &&
298
- (isOutward ? x.outward : x.return).travelDurationMinutes <=
299
- directionFilter.travelDuration.selectedMax
300
- );
301
- return filteredGroups.filter(
302
- (x) =>
303
- directionFilter.changeDuration.selectedMin <=
304
- (isOutward ? x.outward : x.return).changeDurationMinutes &&
305
- (isOutward ? x.outward : x.return).changeDurationMinutes <=
306
- directionFilter.changeDuration.selectedMax
307
- );
308
- };
309
-
310
- export const formatMinutes = (minutes: number) => {
311
- var hh = Math.floor(minutes / 60);
312
- var mm = Math.floor(minutes % 60);
313
- return pad(hh, 2) + ":" + pad(mm, 2);
314
- };
315
-
316
- const getFlightDetails = (flight: BookingPackageFlight) => {
317
- const firstLine = flight.flightMetaData.flightLines[0];
318
- const lastLine =
319
- flight.flightMetaData.flightLines[
320
- flight.flightMetaData.flightLines.length - 1
321
- ];
322
-
323
- const airlineCode = flight.code.split("/")[1];
324
- const waitDurations = getWaitDurations(flight.flightMetaData.flightLines);
325
-
326
- return {
327
- airline: flight.airlineDescription,
328
- airlineCode: airlineCode,
329
- departureDate: firstLine.departureDate,
330
- departureTime: firstLine.departureTime,
331
- departureAirportCode: firstLine.departureAirport,
332
- departureAirport: firstLine.departureAirportDescription,
333
- arrivalDate: lastLine.arrivalDate,
334
- arrivalTime: lastLine.arrivalTime,
335
- arrivalAirport: lastLine.arrivalAirportDescription,
336
- travelDuration: formatDuration(flight.flightMetaData.durationInTicks),
337
- travelDurationMinutes: minutesFromTicks(
338
- flight.flightMetaData.durationInTicks
339
- ),
340
- changeDurationMinutes: getTotalChangeDuration(flight),
341
- numberOfStops: flight.flightMetaData.flightLines.length - 1,
342
- isNextDay: isNextDay(firstLine.departureDate, lastLine.arrivalDate),
343
- travelClass: firstLine.travelClass,
344
- flightLines: flight.flightMetaData.flightLines.map((x, i) => ({
345
- airline: x.operatingAirlineDescription,
346
- departureDate: x.departureDate,
347
- departureTime: x.departureTime,
348
- departureAirport: x.departureAirportDescription,
349
- arrivalDate: x.arrivalDate,
350
- arrivalTime: x.arrivalTime,
351
- arrivalAirport: x.arrivalAirportDescription,
352
- number: `${x.airlineCode} ${x.number}`,
353
- travelDuration: formatDuration(x.durationInTicks),
354
- waitDuration:
355
- waitDurations.length - 1 <= i ? waitDurations[i] : undefined,
356
- })),
357
- } as GroupedFlightDetails;
358
- };
359
-
360
- const isNextDay = (startDateString: string, endDateString: string) => {
361
- const startDate = parseISO(startDateString);
362
- const endDate = parseISO(endDateString);
363
-
364
- return !isEqual(startDate, endDate);
365
- };
366
-
367
- const getWaitDurations = (lines: BookingPackageFlightMetaDataLine[]) => {
368
- if (lines.length <= 1) return [];
369
- let arrivalDate = lines[0].arrivalDate;
370
- let arrivalTime = lines[0].arrivalTime;
371
-
372
- const waitDurations: string[] = [];
373
- for (var i = 1; i < lines.length; i++) {
374
- const line = lines[i];
375
-
376
- const waitDuration = getWaitDuration(
377
- arrivalDate,
378
- arrivalTime,
379
- line.departureDate,
380
- line.departureTime
381
- );
382
- waitDurations.push(waitDuration);
383
-
384
- arrivalDate = line.arrivalDate;
385
- arrivalTime = line.arrivalTime;
386
- }
387
-
388
- return waitDurations;
389
- };
390
-
391
- const getWaitDuration = (
392
- arrivalDateString: string,
393
- arrivalTime: string,
394
- departureDateString: string,
395
- departureTime: string
396
- ) => {
397
- const minutes = getWaitDurationInMinutes(
398
- arrivalDateString,
399
- arrivalTime,
400
- departureDateString,
401
- departureTime
402
- );
403
-
404
- var hh = Math.floor(minutes / 60);
405
- var mm = Math.floor(minutes % 60);
406
- return pad(hh, 2) + ":" + pad(mm, 2);
407
- };
408
-
409
- const getWaitDurationInMinutes = (
410
- arrivalDateString: string,
411
- arrivalTime: string,
412
- departureDateString: string,
413
- departureTime: string
414
- ) => {
415
- const arrivalDate = parseISO(arrivalDateString);
416
- const arrivalTimeParts = arrivalTime.split(":");
417
-
418
- arrivalDate.setHours(parseInt(arrivalTimeParts[0]));
419
- arrivalDate.setMinutes(parseInt(arrivalTimeParts[1]));
420
-
421
- const departureDate = parseISO(departureDateString);
422
- const departureTimeParts = departureTime.split(":");
423
-
424
- departureDate.setHours(parseInt(departureTimeParts[0]));
425
- departureDate.setMinutes(parseInt(departureTimeParts[1]));
426
-
427
- return differenceInMinutes(departureDate, arrivalDate);
428
- };
429
-
430
- /*const groupFlights = (flights: BookingPackageFlight[]) => {
431
- let flightsPool = [...flights];
432
- let groups = [] as FlightGroup[];
433
- for (var i = 0; i < flightsPool.length; i++) {
434
- const flight = flightsPool[i];
435
-
436
- const relatedFlights = flightsPool.filter(x => x != flight
437
- && x.code === flight.code
438
- && isDateEqual(x.startDateTime, flight.startDateTime)
439
- && isDateEqual(x.endDateTime, flight.endDateTime)
440
- );
441
-
442
- flightsPool = flightsPool.filter(x => x != flight
443
- && relatedFlights.some(y => y != x));
444
-
445
- groups.push({
446
- code: flight.code,
447
- startDate: parseISO(flight.startDateTime),
448
- endDate: parseISO(flight.endDateTime),
449
- options: [flight, ...relatedFlights]
450
- });
451
- }
452
- }
453
-
454
- const isDateEqual = (first: string, second: string) => {
455
- const firstDate = parseISO(first);
456
- const secondDate = parseISO(second);
457
-
458
- return isEqual(firstDate, secondDate);
459
- }*/
460
-
461
- const minutesFromTicks = (ticks: number) => {
462
- const totalSeconds = ticks / 10_000_000;
463
- return Math.floor(totalSeconds / 60);
464
- };
465
-
466
- const formatDuration = (ticks: number) => {
467
- if (!ticks) return "";
468
-
469
- const totalSeconds = ticks / 10_000_000;
470
- var hh = Math.floor(totalSeconds / 3600);
471
- var mm = Math.floor((totalSeconds % 3600) / 60);
472
- return pad(hh, 2) + ":" + pad(mm, 2);
473
- };
474
-
475
- const pad = (input: number, width: number) => {
476
- const n = input + "";
477
- return n.length >= width ? n : new Array(width - n.length + 1).join("0") + n;
478
- };
479
-
480
- const determineTimeBracket = (input: string) => {
481
- const time = parseInt(input.replace(":", ""));
482
- if (time <= 500) return "0000-0500";
483
- if (time > 500 && time <= 1200) return "0500-1200";
484
- if (time > 1200 && time <= 1800) return "1201-1800";
485
- return "1800-2400";
486
- };
487
-
488
- const getBracketTranslation = (input: string, translations: any) => {
489
- if (input === "0000-0500") return translations.FLIGHTS_FORM.NIGHT_DEPARTURE;
490
- if (input === "0500-1200") return translations.FLIGHTS_FORM.MORNING_DEPARTURE;
491
- if (input === "1200-1800")
492
- return translations.FLIGHTS_FORM.AFTERNOON_DEPARTURE;
493
- return translations.FLIGHTS_FORM.EVENING_DEPARTURE;
494
- };
495
-
496
- const getTotalChangeDuration = (flight: BookingPackageFlight) => {
497
- const lines = flight.flightMetaData.flightLines;
498
-
499
- if (lines.length <= 1) return 0;
500
- let arrivalDate = lines[0].arrivalDate;
501
- let arrivalTime = lines[0].arrivalTime;
502
-
503
- let waitDuration = 0;
504
- for (var i = 1; i < lines.length; i++) {
505
- const line = lines[i];
506
-
507
- waitDuration += getWaitDurationInMinutes(
508
- arrivalDate,
509
- arrivalTime,
510
- line.departureDate,
511
- line.departureTime
512
- );
513
- }
514
-
515
- return waitDuration;
516
- };
1
+ import {
2
+ BookingPackageFlight,
3
+ BookingPackageFlightMetaDataLine,
4
+ } from "@qite/tide-client/build/types";
5
+ import { differenceInMinutes, isEqual, parseISO } from "date-fns";
6
+ import {
7
+ FlightDirectionFilter,
8
+ FlightFilterOption,
9
+ FlightFilterOptions,
10
+ GroupedFlightDetails,
11
+ GroupedFlights,
12
+ } from "../../types";
13
+
14
+ /*interface FlightGroup {
15
+ code: string;
16
+ startDate: Date,
17
+ endDate: Date;
18
+ options: BookingPackageFlight[];
19
+ }*/
20
+
21
+ export const buildGroupedFlights = (
22
+ outwardFlights: BookingPackageFlight[] | undefined,
23
+ returnFlights: BookingPackageFlight[] | undefined
24
+ ) => {
25
+ if (!outwardFlights || !returnFlights) return [] as GroupedFlights[];
26
+
27
+ // let outwardGroups = groupFlights(outwardFlights);
28
+ // let returnGroups = groupFlights(returnFlights);
29
+
30
+ const pairs: {
31
+ outward: BookingPackageFlight;
32
+ return: BookingPackageFlight;
33
+ }[] = [];
34
+ outwardFlights.forEach((outwardFlight) => {
35
+ if (outwardFlight.externalGuid) {
36
+ const returnFlight = returnFlights.find(
37
+ (x) => x.externalGuid === outwardFlight.externalGuid
38
+ )!;
39
+ pairs.push({ outward: outwardFlight, return: returnFlight });
40
+ } else {
41
+ const outwardCode = outwardFlight.code.substring(0, 7);
42
+ const returnCode = outwardCode.split(" ").reduce((a, b) => `${b} ${a}`);
43
+
44
+ returnFlights
45
+ .filter((x) => x.code.startsWith(returnCode))
46
+ .forEach((returnFlight) => {
47
+ pairs.push({ outward: outwardFlight, return: returnFlight });
48
+ });
49
+ }
50
+ });
51
+
52
+ const results = pairs.map((x) => {
53
+ const outwardFlightDetails = getFlightDetails(x.outward);
54
+ const returnFlightDetails = getFlightDetails(x.return);
55
+
56
+ return {
57
+ isSelected: x.outward.isSelected && x.return.isSelected,
58
+ price: x.outward.price + x.return.price,
59
+ outward: outwardFlightDetails,
60
+ return: returnFlightDetails,
61
+ selectedOutward: x.outward,
62
+ selectedReturn: x.return,
63
+ } as GroupedFlights;
64
+ });
65
+
66
+ return results;
67
+ };
68
+
69
+ export const buildFilterOptions = (
70
+ outwardFlights: BookingPackageFlight[] | undefined,
71
+ returnFlights: BookingPackageFlight[] | undefined,
72
+ translations: any
73
+ ) => {
74
+ if (!outwardFlights || !returnFlights) return undefined;
75
+
76
+ const airports: FlightFilterOption[] = [];
77
+ const airlines: FlightFilterOption[] = [];
78
+ const numberOfStops: FlightFilterOption[] = [];
79
+ const outwardDeparturePeriods: FlightFilterOption[] = [];
80
+ const returnDeparturePeriods: FlightFilterOption[] = [];
81
+
82
+ let lowestDepartureTravelDuration = 9999;
83
+ let highestDepartureTravelDuration = 0;
84
+ let lowestDepartureChangeDuration = 9999;
85
+ let highestDepartureChangeDuration = 0;
86
+
87
+ outwardFlights.forEach((flight) => {
88
+ const airlineCode = flight.code.split("/")[1];
89
+
90
+ if (flight.flightMetaData.flightLines?.length) {
91
+ const firstLine = flight.flightMetaData.flightLines[0];
92
+
93
+ if (!airports.some((x) => x.value === firstLine.departureAirport)) {
94
+ airports.push({
95
+ value: firstLine?.departureAirport,
96
+ label: firstLine.departureAirportDescription,
97
+ count: 0,
98
+ isSelected: false,
99
+ });
100
+ }
101
+ }
102
+
103
+ if (!airlines.some((x) => x.value === airlineCode)) {
104
+ airlines.push({
105
+ value: airlineCode,
106
+ label: flight.airlineDescription,
107
+ count: 0,
108
+ isSelected: false,
109
+ });
110
+ }
111
+
112
+ const stopCount = flight.flightMetaData.flightLines.length - 1;
113
+ if (!numberOfStops.some((x) => x.value === stopCount + "")) {
114
+ numberOfStops.push({
115
+ value: stopCount + "",
116
+ label:
117
+ stopCount === 0
118
+ ? translations.FLIGHTS_FORM.DIRECT_FLIGHT
119
+ : stopCount == 1
120
+ ? `${stopCount} ${translations.FLIGHTS_FORM.STOP}`
121
+ : `${stopCount} ${translations.FLIGHTS_FORM.STOPS}`,
122
+ count: 0,
123
+ isSelected: false,
124
+ });
125
+ }
126
+
127
+ const departureTime = flight.flightMetaData.flightLines[0].departureTime;
128
+ const timeBracket = determineTimeBracket(departureTime);
129
+ if (!outwardDeparturePeriods.some((x) => x.value === timeBracket)) {
130
+ outwardDeparturePeriods.push({
131
+ value: timeBracket,
132
+ label: getBracketTranslation(timeBracket, translations),
133
+ count: 0,
134
+ isSelected: false,
135
+ });
136
+ }
137
+
138
+ const travelDurationInMinutes = minutesFromTicks(
139
+ flight.flightMetaData.durationInTicks
140
+ );
141
+ if (travelDurationInMinutes > highestDepartureTravelDuration)
142
+ highestDepartureTravelDuration = travelDurationInMinutes;
143
+ if (travelDurationInMinutes < lowestDepartureTravelDuration)
144
+ lowestDepartureTravelDuration = travelDurationInMinutes;
145
+
146
+ const changeDurationInMinutes = getTotalChangeDuration(flight);
147
+ if (changeDurationInMinutes > highestDepartureChangeDuration)
148
+ highestDepartureChangeDuration = changeDurationInMinutes;
149
+ if (changeDurationInMinutes < lowestDepartureChangeDuration)
150
+ lowestDepartureChangeDuration = changeDurationInMinutes;
151
+ });
152
+
153
+ let lowestReturnTravelDuration = 9999;
154
+ let highestReturnTravelDuration = 0;
155
+ let lowestReturnChangeDuration = 9999;
156
+ let highestReturnChangeDuration = 0;
157
+
158
+ returnFlights.forEach((flight) => {
159
+ const durationInMinutes = minutesFromTicks(
160
+ flight.flightMetaData.durationInTicks
161
+ );
162
+ if (durationInMinutes > highestReturnTravelDuration)
163
+ highestReturnTravelDuration = durationInMinutes;
164
+ if (durationInMinutes < lowestReturnTravelDuration)
165
+ lowestReturnTravelDuration = durationInMinutes;
166
+
167
+ const changeDurationInMinutes = getTotalChangeDuration(flight);
168
+ if (changeDurationInMinutes > highestReturnChangeDuration)
169
+ highestReturnChangeDuration = changeDurationInMinutes;
170
+ if (changeDurationInMinutes < lowestReturnChangeDuration)
171
+ lowestReturnChangeDuration = changeDurationInMinutes;
172
+
173
+ const departureTime = flight.flightMetaData.flightLines[0].departureTime;
174
+ const timeBracket = determineTimeBracket(departureTime);
175
+ if (!returnDeparturePeriods.some((x) => x.value === timeBracket)) {
176
+ returnDeparturePeriods.push({
177
+ value: timeBracket,
178
+ label: getBracketTranslation(timeBracket, translations),
179
+ count: 0,
180
+ isSelected: false,
181
+ });
182
+ }
183
+ });
184
+
185
+ return {
186
+ airports: airports,
187
+ airlines: airlines,
188
+ numberOfStops: numberOfStops,
189
+ outward: {
190
+ departurePeriod: outwardDeparturePeriods,
191
+ travelDuration: {
192
+ min: lowestDepartureTravelDuration,
193
+ max: highestDepartureTravelDuration,
194
+ selectedMin: lowestDepartureTravelDuration,
195
+ selectedMax: highestDepartureTravelDuration,
196
+ },
197
+ changeDuration: {
198
+ min: lowestDepartureChangeDuration,
199
+ max: highestDepartureChangeDuration,
200
+ selectedMin: lowestDepartureChangeDuration,
201
+ selectedMax: highestDepartureChangeDuration,
202
+ },
203
+ },
204
+ return: {
205
+ departurePeriod: returnDeparturePeriods,
206
+ travelDuration: {
207
+ min: lowestReturnTravelDuration,
208
+ max: highestReturnTravelDuration,
209
+ selectedMin: lowestReturnTravelDuration,
210
+ selectedMax: highestReturnTravelDuration,
211
+ },
212
+ changeDuration: {
213
+ min: lowestReturnChangeDuration,
214
+ max: highestReturnChangeDuration,
215
+ selectedMin: lowestReturnChangeDuration,
216
+ selectedMax: highestReturnChangeDuration,
217
+ },
218
+ },
219
+ } as FlightFilterOptions;
220
+ };
221
+
222
+ export const filterGroupedFlights = (
223
+ groups: GroupedFlights[],
224
+ filterOptions: FlightFilterOptions | undefined
225
+ ) => {
226
+ if (!groups.length || !filterOptions) return [];
227
+
228
+ let filteredGroups = groups;
229
+ if (filterOptions.airlines.some((x) => x.isSelected)) {
230
+ const selectedAirlineCodes = filterOptions.airlines.filter(
231
+ (x) => x.isSelected
232
+ );
233
+ filteredGroups = filteredGroups.filter((x) =>
234
+ selectedAirlineCodes.some((y) => y.value === x.outward.airlineCode)
235
+ );
236
+ }
237
+
238
+ if (filterOptions.airports.some((x) => x.isSelected)) {
239
+ const selectedAirlineCodes = filterOptions.airports.filter(
240
+ (x) => x.isSelected
241
+ );
242
+ filteredGroups = filteredGroups.filter((x) =>
243
+ selectedAirlineCodes.some(
244
+ (y) => y.value === x.outward.departureAirportCode
245
+ )
246
+ );
247
+ }
248
+
249
+ if (filterOptions.numberOfStops.some((x) => x.isSelected)) {
250
+ const selectedNumberOfStops = filterOptions.numberOfStops.filter(
251
+ (x) => x.isSelected
252
+ );
253
+ filteredGroups = filteredGroups.filter((x) =>
254
+ selectedNumberOfStops.some(
255
+ (y) => parseInt(y.value) === x.outward.flightLines.length - 1
256
+ )
257
+ );
258
+ }
259
+
260
+ filteredGroups = filterGroupedFlightByDirection(
261
+ filteredGroups,
262
+ true,
263
+ filterOptions.outward
264
+ );
265
+ filteredGroups = filterGroupedFlightByDirection(
266
+ filteredGroups,
267
+ false,
268
+ filterOptions.return
269
+ );
270
+
271
+ return filteredGroups;
272
+ };
273
+
274
+ const filterGroupedFlightByDirection = (
275
+ groups: GroupedFlights[],
276
+ isOutward: boolean,
277
+ directionFilter: FlightDirectionFilter
278
+ ) => {
279
+ let filteredGroups = groups;
280
+
281
+ if (directionFilter.departurePeriod.some((x) => x.isSelected)) {
282
+ const selectedDeparturePeriods = directionFilter.departurePeriod.filter(
283
+ (x) => x.isSelected
284
+ );
285
+ filteredGroups = filteredGroups.filter((x) =>
286
+ selectedDeparturePeriods.some(
287
+ (y) =>
288
+ y.value ===
289
+ determineTimeBracket((isOutward ? x.outward : x.return).departureTime)
290
+ )
291
+ );
292
+ }
293
+
294
+ filteredGroups = filteredGroups.filter(
295
+ (x) =>
296
+ directionFilter.travelDuration.selectedMin <=
297
+ (isOutward ? x.outward : x.return).travelDurationMinutes &&
298
+ (isOutward ? x.outward : x.return).travelDurationMinutes <=
299
+ directionFilter.travelDuration.selectedMax
300
+ );
301
+ return filteredGroups.filter(
302
+ (x) =>
303
+ directionFilter.changeDuration.selectedMin <=
304
+ (isOutward ? x.outward : x.return).changeDurationMinutes &&
305
+ (isOutward ? x.outward : x.return).changeDurationMinutes <=
306
+ directionFilter.changeDuration.selectedMax
307
+ );
308
+ };
309
+
310
+ export const formatMinutes = (minutes: number) => {
311
+ var hh = Math.floor(minutes / 60);
312
+ var mm = Math.floor(minutes % 60);
313
+ return pad(hh, 2) + ":" + pad(mm, 2);
314
+ };
315
+
316
+ const getFlightDetails = (flight: BookingPackageFlight) => {
317
+ const firstLine = flight.flightMetaData.flightLines[0];
318
+ const lastLine =
319
+ flight.flightMetaData.flightLines[
320
+ flight.flightMetaData.flightLines.length - 1
321
+ ];
322
+
323
+ const airlineCode = flight.code.split("/")[1];
324
+ const waitDurations = getWaitDurations(flight.flightMetaData.flightLines);
325
+
326
+ return {
327
+ airline: flight.airlineDescription,
328
+ airlineCode: airlineCode,
329
+ departureDate: firstLine.departureDate,
330
+ departureTime: firstLine.departureTime,
331
+ departureAirportCode: firstLine.departureAirport,
332
+ departureAirport: firstLine.departureAirportDescription,
333
+ arrivalDate: lastLine.arrivalDate,
334
+ arrivalTime: lastLine.arrivalTime,
335
+ arrivalAirport: lastLine.arrivalAirportDescription,
336
+ travelDuration: formatDuration(flight.flightMetaData.durationInTicks),
337
+ travelDurationMinutes: minutesFromTicks(
338
+ flight.flightMetaData.durationInTicks
339
+ ),
340
+ changeDurationMinutes: getTotalChangeDuration(flight),
341
+ numberOfStops: flight.flightMetaData.flightLines.length - 1,
342
+ isNextDay: isNextDay(firstLine.departureDate, lastLine.arrivalDate),
343
+ travelClass: firstLine.travelClass,
344
+ flightLines: flight.flightMetaData.flightLines.map((x, i) => ({
345
+ airline: x.operatingAirlineDescription,
346
+ departureDate: x.departureDate,
347
+ departureTime: x.departureTime,
348
+ departureAirport: x.departureAirportDescription,
349
+ arrivalDate: x.arrivalDate,
350
+ arrivalTime: x.arrivalTime,
351
+ arrivalAirport: x.arrivalAirportDescription,
352
+ number: `${x.airlineCode} ${x.number}`,
353
+ travelDuration: formatDuration(x.durationInTicks),
354
+ waitDuration:
355
+ waitDurations.length - 1 <= i ? waitDurations[i] : undefined,
356
+ })),
357
+ } as GroupedFlightDetails;
358
+ };
359
+
360
+ const isNextDay = (startDateString: string, endDateString: string) => {
361
+ const startDate = parseISO(startDateString);
362
+ const endDate = parseISO(endDateString);
363
+
364
+ return !isEqual(startDate, endDate);
365
+ };
366
+
367
+ const getWaitDurations = (lines: BookingPackageFlightMetaDataLine[]) => {
368
+ if (lines.length <= 1) return [];
369
+ let arrivalDate = lines[0].arrivalDate;
370
+ let arrivalTime = lines[0].arrivalTime;
371
+
372
+ const waitDurations: string[] = [];
373
+ for (var i = 1; i < lines.length; i++) {
374
+ const line = lines[i];
375
+
376
+ const waitDuration = getWaitDuration(
377
+ arrivalDate,
378
+ arrivalTime,
379
+ line.departureDate,
380
+ line.departureTime
381
+ );
382
+ waitDurations.push(waitDuration);
383
+
384
+ arrivalDate = line.arrivalDate;
385
+ arrivalTime = line.arrivalTime;
386
+ }
387
+
388
+ return waitDurations;
389
+ };
390
+
391
+ const getWaitDuration = (
392
+ arrivalDateString: string,
393
+ arrivalTime: string,
394
+ departureDateString: string,
395
+ departureTime: string
396
+ ) => {
397
+ const minutes = getWaitDurationInMinutes(
398
+ arrivalDateString,
399
+ arrivalTime,
400
+ departureDateString,
401
+ departureTime
402
+ );
403
+
404
+ var hh = Math.floor(minutes / 60);
405
+ var mm = Math.floor(minutes % 60);
406
+ return pad(hh, 2) + ":" + pad(mm, 2);
407
+ };
408
+
409
+ const getWaitDurationInMinutes = (
410
+ arrivalDateString: string,
411
+ arrivalTime: string,
412
+ departureDateString: string,
413
+ departureTime: string
414
+ ) => {
415
+ const arrivalDate = parseISO(arrivalDateString);
416
+ const arrivalTimeParts = arrivalTime.split(":");
417
+
418
+ arrivalDate.setHours(parseInt(arrivalTimeParts[0]));
419
+ arrivalDate.setMinutes(parseInt(arrivalTimeParts[1]));
420
+
421
+ const departureDate = parseISO(departureDateString);
422
+ const departureTimeParts = departureTime.split(":");
423
+
424
+ departureDate.setHours(parseInt(departureTimeParts[0]));
425
+ departureDate.setMinutes(parseInt(departureTimeParts[1]));
426
+
427
+ return differenceInMinutes(departureDate, arrivalDate);
428
+ };
429
+
430
+ /*const groupFlights = (flights: BookingPackageFlight[]) => {
431
+ let flightsPool = [...flights];
432
+ let groups = [] as FlightGroup[];
433
+ for (var i = 0; i < flightsPool.length; i++) {
434
+ const flight = flightsPool[i];
435
+
436
+ const relatedFlights = flightsPool.filter(x => x != flight
437
+ && x.code === flight.code
438
+ && isDateEqual(x.startDateTime, flight.startDateTime)
439
+ && isDateEqual(x.endDateTime, flight.endDateTime)
440
+ );
441
+
442
+ flightsPool = flightsPool.filter(x => x != flight
443
+ && relatedFlights.some(y => y != x));
444
+
445
+ groups.push({
446
+ code: flight.code,
447
+ startDate: parseISO(flight.startDateTime),
448
+ endDate: parseISO(flight.endDateTime),
449
+ options: [flight, ...relatedFlights]
450
+ });
451
+ }
452
+ }
453
+
454
+ const isDateEqual = (first: string, second: string) => {
455
+ const firstDate = parseISO(first);
456
+ const secondDate = parseISO(second);
457
+
458
+ return isEqual(firstDate, secondDate);
459
+ }*/
460
+
461
+ const minutesFromTicks = (ticks: number) => {
462
+ const totalSeconds = ticks / 10_000_000;
463
+ return Math.floor(totalSeconds / 60);
464
+ };
465
+
466
+ const formatDuration = (ticks: number) => {
467
+ if (!ticks) return "";
468
+
469
+ const totalSeconds = ticks / 10_000_000;
470
+ var hh = Math.floor(totalSeconds / 3600);
471
+ var mm = Math.floor((totalSeconds % 3600) / 60);
472
+ return pad(hh, 2) + ":" + pad(mm, 2);
473
+ };
474
+
475
+ const pad = (input: number, width: number) => {
476
+ const n = input + "";
477
+ return n.length >= width ? n : new Array(width - n.length + 1).join("0") + n;
478
+ };
479
+
480
+ const determineTimeBracket = (input: string) => {
481
+ const time = parseInt(input.replace(":", ""));
482
+ if (time <= 500) return "0000-0500";
483
+ if (time > 500 && time <= 1200) return "0500-1200";
484
+ if (time > 1200 && time <= 1800) return "1201-1800";
485
+ return "1800-2400";
486
+ };
487
+
488
+ const getBracketTranslation = (input: string, translations: any) => {
489
+ if (input === "0000-0500") return translations.FLIGHTS_FORM.NIGHT_DEPARTURE;
490
+ if (input === "0500-1200") return translations.FLIGHTS_FORM.MORNING_DEPARTURE;
491
+ if (input === "1200-1800")
492
+ return translations.FLIGHTS_FORM.AFTERNOON_DEPARTURE;
493
+ return translations.FLIGHTS_FORM.EVENING_DEPARTURE;
494
+ };
495
+
496
+ const getTotalChangeDuration = (flight: BookingPackageFlight) => {
497
+ const lines = flight.flightMetaData.flightLines;
498
+
499
+ if (lines.length <= 1) return 0;
500
+ let arrivalDate = lines[0].arrivalDate;
501
+ let arrivalTime = lines[0].arrivalTime;
502
+
503
+ let waitDuration = 0;
504
+ for (var i = 1; i < lines.length; i++) {
505
+ const line = lines[i];
506
+
507
+ waitDuration += getWaitDurationInMinutes(
508
+ arrivalDate,
509
+ arrivalTime,
510
+ line.departureDate,
511
+ line.departureTime
512
+ );
513
+ }
514
+
515
+ return waitDuration;
516
+ };