blob: a7fa8c5a8522883b35d2a379d461dad998a43de8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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}`;
}
|