From c26a0d026886e6f70ea3487b9d83a54d20b9c1e4 Mon Sep 17 00:00:00 2001 From: trisusilo48 Date: Tue, 28 Jan 2025 09:46:11 +0700 Subject: biteship --- src/lib/checkout/utils/functionCheckouit.js | 31 ++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'src/lib/checkout/utils/functionCheckouit.js') diff --git a/src/lib/checkout/utils/functionCheckouit.js b/src/lib/checkout/utils/functionCheckouit.js index b299f289..a6e6c337 100644 --- a/src/lib/checkout/utils/functionCheckouit.js +++ b/src/lib/checkout/utils/functionCheckouit.js @@ -1,17 +1,27 @@ +import { m } from 'framer-motion'; +import { min } from 'moment/moment'; + export function formatShipmentRange( shipmentDurationRange, - shipmentDurationUnit + shipmentDurationUnit, + productSLA ) { if (!shipmentDurationRange || !shipmentDurationUnit) { return ''; } let minRange, maxRange; + console.log('ini masuk', shipmentDurationRange); + // Cek apakah durasi berupa range atau angka tunggal if (shipmentDurationRange.includes('-')) { [minRange, maxRange] = shipmentDurationRange.split(' - ').map(Number); + // if (minRange === maxRange) { + // maxRange = minRange + 3; + // } } else { - minRange = maxRange = Number(shipmentDurationRange); // Jika angka tunggal + minRange = Number(shipmentDurationRange); // Jika angka tunggal + maxRange = Number(shipmentDurationRange) + 3; } const start = new Date(); // Tanggal saat ini @@ -21,19 +31,22 @@ export function formatShipmentRange( // Hitung estimasi berdasarkan unit waktu if (shipmentDurationUnit === 'days' || shipmentDurationUnit === 'day') { minDate = new Date(start); - minDate.setDate(start.getDate() + (minRange + 3)); + minDate.setDate(start.getDate() + (minRange + productSLA)); maxDate = new Date(start); - maxDate.setDate(start.getDate() + (maxRange + 3)); + maxDate.setDate(start.getDate() + (maxRange + productSLA)); } else if (shipmentDurationUnit === 'hours') { - minDate = new Date(start.getTime() + (minRange + 3) * 60 * 60 * 1000); - maxDate = new Date(start.getTime() + (maxRange + 3) * 60 * 60 * 1000); + minDate = new Date(start); + minDate.setDate(start.getDate() + (1 + productSLA)); + + maxDate = new Date(start); + maxDate.setDate(start.getDate() + (1 + productSLA + 1)); + // minDate = new Date(start.getTime() + (minRange + 3) * 60 * 60 * 1000); + // maxDate = new Date(start.getTime() + (maxRange + 3) * 60 * 60 * 1000); } else { throw new Error("Unsupported unit. Please use 'days' or 'hours'."); } - console.log('min max', minDate, maxDate); - const minDateStr = formatDate(minDate); const maxDateStr = formatDate(maxDate); if (minDateStr === maxDateStr) { @@ -60,7 +73,7 @@ export function getToDate(shipmentDurationRange, shipmentDurationUnit) { let maxDate; // Hitung estimasi berdasarkan unit waktu - if (shipmentDurationUnit === 'days' || shipmentDurationUnit === 'day') { + if (shipmentDurationUnit === 'days' || shipmentDurationUnit === 'day') { maxDate = new Date(start); maxDate.setDate(start.getDate() + (maxRange + 3)); } else if (shipmentDurationUnit === 'hours') { -- cgit v1.2.3