feat: optimize UI queries and seed number library

This commit is contained in:
hectorzhao
2026-08-27 20:24:18 +08:00
parent 138297d191
commit 564234b769
22 changed files with 631 additions and 84 deletions
+19
View File
@@ -0,0 +1,19 @@
const pad = (value) => String(value).padStart(2, '0');
export function formatDateInput(date) {
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
}
export function lastSevenDays(reference = new Date()) {
const end = new Date(reference.getFullYear(), reference.getMonth(), reference.getDate());
const start = new Date(end);
start.setDate(start.getDate() - 6);
return { startDate: formatDateInput(start), endDate: formatDateInput(end) };
}
export function dateRangeParams(startDate, endDate, fromKey = 'startedFrom', toKey = 'startedTo') {
const params = {};
if (startDate) params[fromKey] = new Date(`${startDate}T00:00:00`).toISOString();
if (endDate) params[toKey] = new Date(`${endDate}T23:59:59.999`).toISOString();
return params;
}