提交
This commit is contained in:
1 parent
62cfb8fbbf
commit
135dd550b6
2 files changed
+48
No files matched your search
@@ -43,6 +43,37 @@ export function formatPaymentDueDate(d: unknown) {
|
||||
return s
|
||||
}
|
||||
|
||||
/** 分期应缴预警天数(与分期预警规则一致:应缴日在当天起未来 N 天内,含逾期) */
|
||||
export const PAYMENT_DUE_WARN_DAYS = 15
|
||||
|
||||
function parsePaymentDueYmd(ymd: unknown): Date | null {
|
||||
const raw = String(ymd || '').replace(/\D/g, '')
|
||||
if (raw.length !== 8) return null
|
||||
const y = Number(raw.slice(0, 4))
|
||||
const m = Number(raw.slice(4, 6)) - 1
|
||||
const d = Number(raw.slice(6, 8))
|
||||
const dt = new Date(y, m, d)
|
||||
if (dt.getFullYear() !== y || dt.getMonth() !== m || dt.getDate() !== d) return null
|
||||
return dt
|
||||
}
|
||||
|
||||
function startOfLocalDay(d: Date) {
|
||||
return new Date(d.getFullYear(), d.getMonth(), d.getDate())
|
||||
}
|
||||
|
||||
/** 应缴日是否不晚于「今天 + warnDays」(含当天与已逾期) */
|
||||
export function isPaymentDueWithinWarnWindow(
|
||||
installmentDueDate: unknown,
|
||||
warnDays = PAYMENT_DUE_WARN_DAYS
|
||||
) {
|
||||
const due = parsePaymentDueYmd(installmentDueDate)
|
||||
if (!due) return false
|
||||
const today = startOfLocalDay(new Date())
|
||||
const limit = new Date(today)
|
||||
limit.setDate(limit.getDate() + warnDays)
|
||||
return due.getTime() <= limit.getTime()
|
||||
}
|
||||
|
||||
export function formatPaymentAmount(v: unknown) {
|
||||
if (v == null || v === '') return '-'
|
||||
const n = Number(v)
|
||||
|
||||
Reference in new issue
Block a user