You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.1 KiB
35 lines
1.1 KiB
import { p1DateFromIso, p1DateToIso } from "@/lib/priority1/date-format";
|
|
|
|
/** 提货日最早可选:明天(不含今天) */
|
|
export function minPickupDateIso(): string {
|
|
const d = new Date();
|
|
d.setHours(12, 0, 0, 0);
|
|
d.setDate(d.getDate() + 1);
|
|
const y = d.getFullYear();
|
|
const m = String(d.getMonth() + 1).padStart(2, "0");
|
|
const day = String(d.getDate()).padStart(2, "0");
|
|
return `${y}-${m}-${day}`;
|
|
}
|
|
|
|
/** MM/DD/YYYY 形式的最早可选提货日 */
|
|
export function minPickupDateDisplay(): string {
|
|
return p1DateFromIso(minPickupDateIso());
|
|
}
|
|
|
|
/** 提货日须严格晚于今天(按日历日比较,避免时区边界误判) */
|
|
export function isPickupDateAfterToday(display: string): boolean {
|
|
const iso = p1DateToIso(display.trim());
|
|
if (!iso) return false;
|
|
return iso >= minPickupDateIso();
|
|
}
|
|
|
|
export function pickupDateValidationMessage(display: string): string | null {
|
|
if (!/^\d{2}\/\d{2}\/\d{4}$/.test(display.trim())) {
|
|
return "请选择提货日";
|
|
}
|
|
if (!isPickupDateAfterToday(display)) {
|
|
return "提货日须晚于今天";
|
|
}
|
|
return null;
|
|
}
|