eigent/server/app/component/time_friendly.py
2025-08-20 23:05:54 +08:00

24 lines
676 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from datetime import datetime, timedelta
import arrow
def to_date(time: str, format: str | None = None):
try:
if format:
return arrow.get(time, format).date()
else:
return arrow.get(time).date()
except Exception as e:
return None
def monday_start_time() -> datetime:
# 获取当前时间
now = datetime.now()
# 计算今天是本周的第几天星期一是0星期天是6
weekday = now.weekday()
# 计算本周一的日期
monday = now - timedelta(days=weekday)
# 设置时间为 0 点
return monday.replace(hour=0, minute=0, second=0, microsecond=0)