b2m-utils 0.0.115 → 0.0.116

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/index.js CHANGED
@@ -515,6 +515,66 @@ function isValid(date) {
515
515
  return !isNaN(Number(_date));
516
516
  }
517
517
 
518
+ /**
519
+ * The {@link eachDayOfInterval} function options.
520
+ */
521
+
522
+ /**
523
+ * @name eachDayOfInterval
524
+ * @category Interval Helpers
525
+ * @summary Return the array of dates within the specified time interval.
526
+ *
527
+ * @description
528
+ * Return the array of dates within the specified time interval.
529
+ *
530
+ * @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).
531
+ *
532
+ * @param interval - The interval.
533
+ * @param options - An object with options.
534
+ *
535
+ * @returns The array with starts of days from the day of the interval start to the day of the interval end
536
+ *
537
+ * @example
538
+ * // Each day between 6 October 2014 and 10 October 2014:
539
+ * const result = eachDayOfInterval({
540
+ * start: new Date(2014, 9, 6),
541
+ * end: new Date(2014, 9, 10)
542
+ * })
543
+ * //=> [
544
+ * // Mon Oct 06 2014 00:00:00,
545
+ * // Tue Oct 07 2014 00:00:00,
546
+ * // Wed Oct 08 2014 00:00:00,
547
+ * // Thu Oct 09 2014 00:00:00,
548
+ * // Fri Oct 10 2014 00:00:00
549
+ * // ]
550
+ */
551
+ function eachDayOfInterval(interval, options) {
552
+ const startDate = toDate(interval.start);
553
+ const endDate = toDate(interval.end);
554
+
555
+ let reversed = +startDate > +endDate;
556
+ const endTime = reversed ? +startDate : +endDate;
557
+ const currentDate = reversed ? endDate : startDate;
558
+ currentDate.setHours(0, 0, 0, 0);
559
+
560
+ let step = options?.step ?? 1;
561
+ if (!step) return [];
562
+ if (step < 0) {
563
+ step = -step;
564
+ reversed = !reversed;
565
+ }
566
+
567
+ const dates = [];
568
+
569
+ while (+currentDate <= endTime) {
570
+ dates.push(toDate(currentDate));
571
+ currentDate.setDate(currentDate.getDate() + step);
572
+ currentDate.setHours(0, 0, 0, 0);
573
+ }
574
+
575
+ return reversed ? dates.reverse() : dates;
576
+ }
577
+
518
578
  /**
519
579
  * @name startOfYear
520
580
  * @category Year Helpers
@@ -6028,6 +6088,65 @@ var getContractRouteFromFreight = function (contracts, freight) {
6028
6088
  return false;
6029
6089
  };
6030
6090
 
6091
+ var getRouteDeliveryTimeFromFreight = function (freight, contracts) {
6092
+ var _a;
6093
+ var route = getContractRouteFromFreight(contracts, freight);
6094
+ if (freight.cteAt && freight.deliveredAt) {
6095
+ if (route) {
6096
+ var freightStarts = parse(formatDateString(freight.cteAt), "yyyy-MM-dd HH:mm:ss", new Date());
6097
+ var freightsEnds = parse(formatDateString(freight.deliveredAt), "yyyy-MM-dd HH:mm:ss", new Date());
6098
+ if (freightStarts < freightsEnds) {
6099
+ var daysDifference = eachDayOfInterval({
6100
+ start: freightStarts,
6101
+ end: freightsEnds,
6102
+ });
6103
+ if (daysDifference instanceof Array) {
6104
+ var daysToDeliveryArray_1 = (_a = route.daysToDelivery) === null || _a === void 0 ? void 0 : _a.split(',').map(function (it) { return +it; });
6105
+ var daysToDeliveryQtd = daysDifference.filter(function (date) {
6106
+ var dateDay = date.getDay();
6107
+ return daysToDeliveryArray_1.includes(dateDay);
6108
+ });
6109
+ if (daysToDeliveryQtd.length) {
6110
+ return daysToDeliveryQtd.length - 1;
6111
+ }
6112
+ }
6113
+ }
6114
+ }
6115
+ }
6116
+ return 'ND';
6117
+ };
6118
+
6119
+ var getRouteOnTimeFromFreight = function (freight, contracts) {
6120
+ var _a;
6121
+ var route = getContractRouteFromFreight(contracts, freight);
6122
+ if (route) {
6123
+ if (freight.cteAt && freight.deliveredAt) {
6124
+ var contract = getContractFromFreight(contracts, freight);
6125
+ if (contract) {
6126
+ var freightStarts = parse(formatDateString(freight.cteAt), "yyyy-MM-dd HH:mm:ss", new Date());
6127
+ var freightEnds = parse(formatDateString(freight.deliveredAt), "yyyy-MM-dd HH:mm:ss", new Date());
6128
+ if (freightStarts < freightEnds) {
6129
+ var daysDifference = eachDayOfInterval({
6130
+ start: freightStarts,
6131
+ end: freightEnds,
6132
+ });
6133
+ if (daysDifference instanceof Array) {
6134
+ var daysToDeliveryArray_1 = (_a = route.daysToDelivery) === null || _a === void 0 ? void 0 : _a.split(',').map(function (it) { return +it; });
6135
+ var daysToDeliveryQtd = daysDifference.filter(function (date) {
6136
+ var dateDay = date.getDay();
6137
+ return daysToDeliveryArray_1 === null || daysToDeliveryArray_1 === void 0 ? void 0 : daysToDeliveryArray_1.includes(dateDay);
6138
+ });
6139
+ if (daysToDeliveryQtd.length) {
6140
+ return (daysToDeliveryQtd.length - 1) <= route.transitTime ? 'Sim' : 'Não';
6141
+ }
6142
+ }
6143
+ }
6144
+ }
6145
+ }
6146
+ }
6147
+ return 'ND';
6148
+ };
6149
+
6031
6150
  function getConfigurationFromDomain(domainConfigurations, configurationName) {
6032
6151
  return domainConfigurations.find(function (i) { return i.name === configurationName; });
6033
6152
  }
@@ -6323,5 +6442,7 @@ exports.getContractRouteFromFreight = getContractRouteFromFreight;
6323
6442
  exports.getCookies = getCookies;
6324
6443
  exports.getDataFromToken = getDataFromToken;
6325
6444
  exports.getFormattedFreightPlaceName = getFormattedFreightPlaceName;
6445
+ exports.getRouteDeliveryTimeFromFreight = getRouteDeliveryTimeFromFreight;
6446
+ exports.getRouteOnTimeFromFreight = getRouteOnTimeFromFreight;
6326
6447
  exports.setFormattedDatesInObjects = setFormattedDatesInObjects;
6327
6448
  //# sourceMappingURL=index.js.map
package/build/index.js.gz CHANGED
Binary file