Agent-Logs-Url: https://github.com/pdf114514/CarReservation/sessions/c0a4b7dc-228e-4e7d-a985-61b9a17de159 Co-authored-by: pdf114514 <57948770+pdf114514@users.noreply.github.com>
39 lines
1.5 KiB
JavaScript
39 lines
1.5 KiB
JavaScript
/**
|
|
* Returns true if the given inspection expiry date string is within 1 month
|
|
* from today (or already past).
|
|
* @param {string} inspectionExpiry - ISO date string (YYYY-MM-DD) or empty
|
|
* @returns {boolean}
|
|
*/
|
|
export function isInspectionExpirySoon(inspectionExpiry) {
|
|
if (!inspectionExpiry) return false;
|
|
const expiry = new Date(inspectionExpiry);
|
|
const oneMonthLater = new Date();
|
|
oneMonthLater.setMonth(oneMonthLater.getMonth() + 1);
|
|
return expiry <= oneMonthLater;
|
|
}
|
|
|
|
/**
|
|
* Formats a date range with optional AM/PM periods into a display string.
|
|
* @param {string} startDate - ISO date string (YYYY-MM-DD)
|
|
* @param {string} startPeriod - '午前', '午後', or ''
|
|
* @param {string} endDate - ISO date string (YYYY-MM-DD)
|
|
* @param {string} endPeriod - '午前', '午後', or ''
|
|
* @returns {string}
|
|
*/
|
|
export function formatDateRange(startDate, startPeriod, endDate, endPeriod) {
|
|
const start = startDate.slice(5) + (startPeriod ? ' ' + startPeriod : '');
|
|
const end = endDate.slice(5) + (endPeriod ? ' ' + endPeriod : '');
|
|
return `${start} 〜 ${end}`;
|
|
}
|
|
|
|
/**
|
|
* Formats a reservation tooltip string with full dates and optional periods.
|
|
* @param {object} r - reservation object
|
|
* @returns {string}
|
|
*/
|
|
export function formatReservationTooltip(r) {
|
|
const start = r.start_date + (r.start_period ? ' ' + r.start_period : '');
|
|
const end = r.end_date + (r.end_period ? ' ' + r.end_period : '');
|
|
return `${r.customer_name || '予約'}\n${start} 〜 ${end}${r.notes ? '\n' + r.notes : ''}`;
|
|
}
|