b2m-utils 0.0.115 → 0.0.117

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.
@@ -0,0 +1,2 @@
1
+ import { DomainSlaContract, SlaFreight } from "../../types";
2
+ export declare const getRouteDeliveryTimeFromFreight: (freight: SlaFreight, contracts: DomainSlaContract[]) => number | "ND";
@@ -0,0 +1,2 @@
1
+ import { DomainSlaContract, SlaFreight } from "../../types";
2
+ export declare const getRouteOnTimeFromFreight: (freight: SlaFreight, contracts: DomainSlaContract[]) => boolean;
@@ -1,5 +1,7 @@
1
1
  export * from './getContractFromFreight';
2
2
  export * from './getContractRouteFromFreight';
3
+ export * from './getRouteDeliveryTimeFromFreight';
4
+ export * from './getRouteOnTimeFromFreight';
3
5
  export * from './formatDateString';
4
6
  export * from './getConfigurationFromDomain';
5
7
  export * from './getCookies';
@@ -511,6 +511,66 @@ function isValid(date) {
511
511
  return !isNaN(Number(_date));
512
512
  }
513
513
 
514
+ /**
515
+ * The {@link eachDayOfInterval} function options.
516
+ */
517
+
518
+ /**
519
+ * @name eachDayOfInterval
520
+ * @category Interval Helpers
521
+ * @summary Return the array of dates within the specified time interval.
522
+ *
523
+ * @description
524
+ * Return the array of dates within the specified time interval.
525
+ *
526
+ * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
527
+ *
528
+ * @param interval - The interval.
529
+ * @param options - An object with options.
530
+ *
531
+ * @returns The array with starts of days from the day of the interval start to the day of the interval end
532
+ *
533
+ * @example
534
+ * // Each day between 6 October 2014 and 10 October 2014:
535
+ * const result = eachDayOfInterval({
536
+ * start: new Date(2014, 9, 6),
537
+ * end: new Date(2014, 9, 10)
538
+ * })
539
+ * //=> [
540
+ * // Mon Oct 06 2014 00:00:00,
541
+ * // Tue Oct 07 2014 00:00:00,
542
+ * // Wed Oct 08 2014 00:00:00,
543
+ * // Thu Oct 09 2014 00:00:00,
544
+ * // Fri Oct 10 2014 00:00:00
545
+ * // ]
546
+ */
547
+ function eachDayOfInterval(interval, options) {
548
+ const startDate = toDate(interval.start);
549
+ const endDate = toDate(interval.end);
550
+
551
+ let reversed = +startDate > +endDate;
552
+ const endTime = reversed ? +startDate : +endDate;
553
+ const currentDate = reversed ? endDate : startDate;
554
+ currentDate.setHours(0, 0, 0, 0);
555
+
556
+ let step = options?.step ?? 1;
557
+ if (!step) return [];
558
+ if (step < 0) {
559
+ step = -step;
560
+ reversed = !reversed;
561
+ }
562
+
563
+ const dates = [];
564
+
565
+ while (+currentDate <= endTime) {
566
+ dates.push(toDate(currentDate));
567
+ currentDate.setDate(currentDate.getDate() + step);
568
+ currentDate.setHours(0, 0, 0, 0);
569
+ }
570
+
571
+ return reversed ? dates.reverse() : dates;
572
+ }
573
+
514
574
  /**
515
575
  * @name startOfYear
516
576
  * @category Year Helpers
@@ -6024,6 +6084,65 @@ var getContractRouteFromFreight = function (contracts, freight) {
6024
6084
  return false;
6025
6085
  };
6026
6086
 
6087
+ var getRouteDeliveryTimeFromFreight = function (freight, contracts) {
6088
+ var _a;
6089
+ var route = getContractRouteFromFreight(contracts, freight);
6090
+ if (freight.cteAt && freight.deliveredAt) {
6091
+ if (route) {
6092
+ var freightStarts = parse(formatDateString(freight.cteAt), "yyyy-MM-dd HH:mm:ss", new Date());
6093
+ var freightsEnds = parse(formatDateString(freight.deliveredAt), "yyyy-MM-dd HH:mm:ss", new Date());
6094
+ if (freightStarts < freightsEnds) {
6095
+ var daysDifference = eachDayOfInterval({
6096
+ start: freightStarts,
6097
+ end: freightsEnds,
6098
+ });
6099
+ if (daysDifference instanceof Array) {
6100
+ var daysToDeliveryArray_1 = (_a = route.daysToDelivery) === null || _a === void 0 ? void 0 : _a.split(',').map(function (it) { return +it; });
6101
+ var daysToDeliveryQtd = daysDifference.filter(function (date) {
6102
+ var dateDay = date.getDay();
6103
+ return daysToDeliveryArray_1.includes(dateDay);
6104
+ });
6105
+ if (daysToDeliveryQtd.length) {
6106
+ return daysToDeliveryQtd.length - 1;
6107
+ }
6108
+ }
6109
+ }
6110
+ }
6111
+ }
6112
+ return 'ND';
6113
+ };
6114
+
6115
+ var getRouteOnTimeFromFreight = function (freight, contracts) {
6116
+ var _a;
6117
+ var route = getContractRouteFromFreight(contracts, freight);
6118
+ if (route) {
6119
+ if (freight.cteAt && freight.deliveredAt) {
6120
+ var contract = getContractFromFreight(contracts, freight);
6121
+ if (contract) {
6122
+ var freightStarts = parse(formatDateString(freight.cteAt), "yyyy-MM-dd HH:mm:ss", new Date());
6123
+ var freightEnds = parse(formatDateString(freight.deliveredAt), "yyyy-MM-dd HH:mm:ss", new Date());
6124
+ if (freightStarts < freightEnds) {
6125
+ var daysDifference = eachDayOfInterval({
6126
+ start: freightStarts,
6127
+ end: freightEnds,
6128
+ });
6129
+ if (daysDifference instanceof Array) {
6130
+ var daysToDeliveryArray_1 = (_a = route.daysToDelivery) === null || _a === void 0 ? void 0 : _a.split(',').map(function (it) { return +it; });
6131
+ var daysToDeliveryQtd = daysDifference.filter(function (date) {
6132
+ var dateDay = date.getDay();
6133
+ return daysToDeliveryArray_1 === null || daysToDeliveryArray_1 === void 0 ? void 0 : daysToDeliveryArray_1.includes(dateDay);
6134
+ });
6135
+ if (daysToDeliveryQtd.length) {
6136
+ return (daysToDeliveryQtd.length - 1) <= route.transitTime;
6137
+ }
6138
+ }
6139
+ }
6140
+ }
6141
+ }
6142
+ }
6143
+ return false;
6144
+ };
6145
+
6027
6146
  function getConfigurationFromDomain(domainConfigurations, configurationName) {
6028
6147
  return domainConfigurations.find(function (i) { return i.name === configurationName; });
6029
6148
  }
@@ -6312,5 +6431,5 @@ var setFormattedDatesInObjects = function (objectFormat) { return __awaiter(void
6312
6431
  });
6313
6432
  }); };
6314
6433
 
6315
- export { ApplicationColumnNameEnum, ApplicationEnum, CountryEnum, CurrencyEnum, DomainConfigurationEnum, DomainTypeEnum, FeeCalculationTypeEnum, FeeCategoryEnum, ModalEnum, NotificationTypeEnum, PermissionEnum, SpotStatusEnum, TrackProcessProviderTypeEnum, formatDateString, getConfigurationFromDomain, getContractFromFreight, getContractRouteFromFreight, getCookies, getDataFromToken, getFormattedFreightPlaceName, setFormattedDatesInObjects };
6434
+ export { ApplicationColumnNameEnum, ApplicationEnum, CountryEnum, CurrencyEnum, DomainConfigurationEnum, DomainTypeEnum, FeeCalculationTypeEnum, FeeCategoryEnum, ModalEnum, NotificationTypeEnum, PermissionEnum, SpotStatusEnum, TrackProcessProviderTypeEnum, formatDateString, getConfigurationFromDomain, getContractFromFreight, getContractRouteFromFreight, getCookies, getDataFromToken, getFormattedFreightPlaceName, getRouteDeliveryTimeFromFreight, getRouteOnTimeFromFreight, setFormattedDatesInObjects };
6316
6435
  //# sourceMappingURL=index.esm.js.map
Binary file