diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2025-06-16 02:05:40 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2025-06-16 02:05:40 +0000 |
| commit | 755163a9f803e6959afb4568baa55538b9628cab (patch) | |
| tree | 4469b0d7c6e8b2a7185b271d9589e8de4724d4f2 /src/lib/checkout/utils/functionCheckouit.js | |
| parent | 5669295b8cff1a9c9e559dd263599123a2ad6e92 (diff) | |
| parent | 8ca6c0aa1b2a578332ff1c3706f58530f549352e (diff) | |
Merged in biteship-merge (pull request #420)
Biteship merge
Diffstat (limited to 'src/lib/checkout/utils/functionCheckouit.js')
| -rw-r--r-- | src/lib/checkout/utils/functionCheckouit.js | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/lib/checkout/utils/functionCheckouit.js b/src/lib/checkout/utils/functionCheckouit.js new file mode 100644 index 00000000..a7fa8c5a --- /dev/null +++ b/src/lib/checkout/utils/functionCheckouit.js @@ -0,0 +1,92 @@ +import { m } from 'framer-motion'; +import { min } from 'moment/moment'; + +export function formatShipmentRange( + shipmentDurationRange, + shipmentDurationUnit, + productSLA +) { + if (!shipmentDurationRange || !shipmentDurationUnit) { + return ''; + } + let minRange, maxRange; + + console.log('ini masuk format shipment range', shipmentDurationRange, shipmentDurationUnit, productSLA); + + // 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 = Number(shipmentDurationRange); // Jika angka tunggal + maxRange = Number(shipmentDurationRange); + } + + const start = new Date(); // Tanggal saat ini + + let minDate, maxDate; + + // Hitung estimasi berdasarkan unit waktu + if (shipmentDurationUnit === 'days' || shipmentDurationUnit === 'day') { + minDate = new Date(start); + minDate.setDate(start.getDate() + (minRange + productSLA)); + + maxDate = new Date(start); + maxDate.setDate(start.getDate() + (maxRange + productSLA)); + } else if (shipmentDurationUnit === 'hours') { + 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'."); + } + + const minDateStr = formatDate(minDate); + const maxDateStr = formatDate(maxDate); + if (minDateStr === maxDateStr) { + return `Estimasi tiba ${minDateStr}`; + } + return `Estimasi tiba ${minDateStr} - ${maxDateStr}`; +} + +export function getToDate(shipmentDurationRange, shipmentDurationUnit) { + if (!shipmentDurationRange || !shipmentDurationUnit) { + return ''; + } + const start = new Date(); // Tanggal saat ini + + let maxRange; + + // Cek apakah durasi berupa range atau angka tunggal + if (shipmentDurationRange.includes('-')) { + [, maxRange] = shipmentDurationRange.split(' - ').map(Number); + } else { + maxRange = Number(shipmentDurationRange); // Jika angka tunggal + } + + let maxDate; + + // Hitung estimasi berdasarkan unit waktu + if (shipmentDurationUnit === 'days' || shipmentDurationUnit === 'day') { + maxDate = new Date(start); + maxDate.setDate(start.getDate() + (maxRange + 3)); + } else if (shipmentDurationUnit === 'hours') { + maxDate = new Date(start.getTime() + (maxRange + 3) * 60 * 60 * 1000); + } else { + throw new Error("Unsupported unit. Please use 'days' or 'hours'."); + } + + return maxDate.getDate(); +} + +function formatDate(date) { + const day = date.getDate(); + const month = date.toLocaleString('default', { month: 'short' }); + return `${day} ${month}`; +} |
