Python 后端提交

Python 后端(FastAPI + FastMCP + ...)的初始版本号设定为 0.1.0,这是 uv 在 pypriject.toml
里给我自动设置的,我觉得有道理。
This commit is contained in:
2026-04-21 13:38:46 +08:00
parent 14eadaab86
commit b284c3c260
27 changed files with 1691 additions and 0 deletions

29
router/enhance/week.py Normal file
View File

@@ -0,0 +1,29 @@
"""学期-星期计算"""
from datetime import date, timedelta
def get_semester_week_info(start: date, target: date) -> tuple[int, int]:
"""
给定学期开始日期(第一周周一)和另一指定日期,计算指定的日期是第几周的星期几。
Args:
start: 学期开始的日期date
target: 指定日期date
Returns:
包含两个数字的元组,分别为第几周和星期几。
"""
return (target - start).days // 7 + 1, target.isoweekday()
def get_week_day_info(target: date) -> tuple[date, date]:
"""
给定一个指定日期,获取该日所在的星期的周一和周日的日期。
Args:
target: 指定日期date
Returns:
包含两个 date 的元组,分别为周一和周日。
"""
weekday_int = target.weekday()
return target - timedelta(days=weekday_int), target + timedelta(days=6 - weekday_int)