27 lines
947 B
Python
27 lines
947 B
Python
"""报销模块日期范围工具(从 bx-backend 迁移)。"""
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
def current_month_bounds(now: datetime | None = None) -> tuple[datetime, datetime]:
|
|
"""当前自然月 [month_start, next_month_start)。"""
|
|
if now is None:
|
|
now = datetime.now()
|
|
month_start = now.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
|
|
if now.month == 12:
|
|
month_end = datetime(now.year + 1, 1, 1)
|
|
else:
|
|
month_end = datetime(now.year, now.month + 1, 1)
|
|
return month_start, month_end
|
|
|
|
|
|
def parse_create_time_day_bounds(apply_date: str | None) -> tuple[datetime, datetime] | None:
|
|
if not apply_date or not str(apply_date).strip():
|
|
return None
|
|
try:
|
|
day_start = datetime.strptime(str(apply_date).strip(), "%Y-%m-%d")
|
|
return day_start, day_start + timedelta(days=1)
|
|
except ValueError:
|
|
return None
|