tripstorekrabi-shared 1.9.2 → 1.9.4
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/package.json +1 -1
- package/utils.js +22 -10
package/package.json
CHANGED
package/utils.js
CHANGED
|
@@ -94,8 +94,8 @@ export function getPickuptimeSummary(pickupZones) {
|
|
|
94
94
|
if (pickupZones) {
|
|
95
95
|
let pickupTimesArray = [];
|
|
96
96
|
pickupZones.forEach((pickupZone) => {
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
let pickupLength = pickupZone.indexOf(": ");
|
|
98
|
+
let pickupTimes = pickupZone.substring(pickupLength + 1).trim();
|
|
99
99
|
if (pickupZone.indexOf(" / ") != -1) {
|
|
100
100
|
pickupTimesArray.push(pickupTimes.split(" / "));
|
|
101
101
|
} else {
|
|
@@ -244,7 +244,7 @@ export function transformToNCols(array, n) {
|
|
|
244
244
|
|
|
245
245
|
function chunkArray(array, chunk_size) {
|
|
246
246
|
array = [...array];
|
|
247
|
-
|
|
247
|
+
let results = [];
|
|
248
248
|
|
|
249
249
|
while (array.length) {
|
|
250
250
|
results.push(array.splice(0, chunk_size));
|
|
@@ -397,9 +397,9 @@ export function validateSchedule(schedule, schedules = [], context) {
|
|
|
397
397
|
if (schedule === "?") {
|
|
398
398
|
return true;
|
|
399
399
|
} else if (schedule.indexOf(" - ") != -1) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
400
|
+
let times = schedule.split(" - ");
|
|
401
|
+
let from = times[0];
|
|
402
|
+
let to = times[1];
|
|
403
403
|
|
|
404
404
|
if (!SCHEDULE_PATTERN.test(from) || !SCHEDULE_PATTERN.test(to) || (from === to)) {
|
|
405
405
|
return context.createError({ message: "Invalid schedule format: for example use '09:00 - 15:30'", path: context.path, });
|
|
@@ -427,9 +427,9 @@ export function validatePickupTime(pickupTime, schedule = "", context) {
|
|
|
427
427
|
if (pickupTime === "?" || schedule === "?") {
|
|
428
428
|
return true;
|
|
429
429
|
} else if (pickupTime.indexOf(" - ") != -1) {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
430
|
+
let times = pickupTime.split(" - ");
|
|
431
|
+
let from = times[0];
|
|
432
|
+
let to = times[1];
|
|
433
433
|
|
|
434
434
|
if (!SCHEDULE_PATTERN.test(from) || !SCHEDULE_PATTERN.test(to) || (from === to)) {
|
|
435
435
|
return context.createError({ message: "Invalid pickup time format: for example use '09:00' or '08:45 - 09:00'" });
|
|
@@ -447,6 +447,18 @@ export function validatePickupTime(pickupTime, schedule = "", context) {
|
|
|
447
447
|
}
|
|
448
448
|
}
|
|
449
449
|
|
|
450
|
+
export function isPickupTimeBeforeDepartureTime(schedule, pickupTime) {
|
|
451
|
+
let departureTime = schedule.split(" - ")[0];
|
|
452
|
+
if (pickupTime === "?" || schedule === "?") {
|
|
453
|
+
return false;
|
|
454
|
+
} else if (pickupTime.indexOf(" - ") != -1) {
|
|
455
|
+
let times = pickupTime.split(" - ");
|
|
456
|
+
pickupTime = times[0];
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
return checkTime(pickupTime, departureTime);
|
|
460
|
+
}
|
|
461
|
+
|
|
450
462
|
function checkTime(pickupTimeValue, departureTimeValue, context) {
|
|
451
463
|
if (pickupTimeValue === "" || departureTimeValue === "") {
|
|
452
464
|
return false;
|
|
@@ -459,7 +471,7 @@ function checkTime(pickupTimeValue, departureTimeValue, context) {
|
|
|
459
471
|
let departureTimeValues = departureTimeValue.split(":");
|
|
460
472
|
let departureTime = dayjs().hour(departureTimeValues[0]).minute(departureTimeValues[1]).second(0);
|
|
461
473
|
|
|
462
|
-
return pickupTime.isSameOrBefore(departureTime) ? true : context.createError({ message: "Pickup time should be before or equals departure time", path: context.path, params: { status: "warning" } });
|
|
474
|
+
return pickupTime.isSameOrBefore(departureTime) ? true : context ? context.createError({ message: "Pickup time should be before or equals departure time", path: context.path, params: { status: "warning" } }) : false;
|
|
463
475
|
} catch (e) {
|
|
464
476
|
return false;
|
|
465
477
|
}
|