Also add the confirmation kit implementation plan. Co-authored-by: Cursor <cursoragent@cursor.com>
15 lines
719 B
TypeScript
15 lines
719 B
TypeScript
/** 入职日 + 试用期月数 → YYYY-MM-DD;非法返回 null。按自然月加,日溢出钳到目标月最后一天。 */
|
|
export function addMonthsYmd(hireYmd: string, months: number): string | null {
|
|
const s = String(hireYmd || '').trim()
|
|
if (!/^\d{4}-\d{2}-\d{2}$/.test(s)) return null
|
|
if (!Number.isInteger(months) || months < 0) return null
|
|
const [y, m, d] = s.split('-').map((x) => Number(x))
|
|
if (!y || !m || !d) return null
|
|
const total = y * 12 + (m - 1) + months
|
|
const ny = Math.floor(total / 12)
|
|
const nm = (total % 12) + 1
|
|
const lastDay = new Date(ny, nm, 0).getDate()
|
|
const nd = Math.min(d, lastDay)
|
|
return `${ny}-${String(nm).padStart(2, '0')}-${String(nd).padStart(2, '0')}`
|
|
}
|