Also add the confirmation kit implementation plan. Co-authored-by: Cursor <cursoragent@cursor.com>
30 lines
834 B
Python
30 lines
834 B
Python
"""转正套件:入职日 + 试用期月数 → 建议转正日(YYYY-MM-DD)。"""
|
|
from __future__ import annotations
|
|
|
|
import calendar
|
|
import re
|
|
from datetime import date
|
|
from typing import Optional
|
|
|
|
_YMD = re.compile(r"^(\d{4})-(\d{2})-(\d{2})$")
|
|
|
|
|
|
def add_months_ymd(hire_ymd: str, months: int) -> Optional[str]:
|
|
s = (hire_ymd or "").strip()
|
|
m = _YMD.match(s)
|
|
if not m:
|
|
return None
|
|
if not isinstance(months, int) or isinstance(months, bool) or months < 0:
|
|
return None
|
|
y, mo, d = int(m.group(1)), int(m.group(2)), int(m.group(3))
|
|
try:
|
|
date(y, mo, d)
|
|
except ValueError:
|
|
return None
|
|
total = y * 12 + (mo - 1) + months
|
|
ny, nm = divmod(total, 12)
|
|
nm += 1
|
|
last = calendar.monthrange(ny, nm)[1]
|
|
nd = min(d, last)
|
|
return f"{ny:04d}-{nm:02d}-{nd:02d}"
|