time_tools.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # -*- coding: utf-8 -*-
  2. """
  3. 系统时间工具模块
  4. 提供获取当前系统时间的工具函数,供配风计划审查智能体在版本审查、
  5. 编制时间审查等场景中判断配风日期的时效性。
  6. 工具列表:
  7. - get_current_time: 获取当前系统日期时间
  8. """
  9. from datetime import datetime, timezone, timedelta
  10. # 中国标准时间 (UTC+8)
  11. _CHINA_TZ = timezone(timedelta(hours=8))
  12. def get_current_time() -> str:
  13. """获取当前系统日期时间。
  14. 返回当前日期时间的多种格式,便于智能体在审查配风计划时判断时效性:
  15. - 当前日期时间(中国标准时间 CST,UTC+8)
  16. - 当前年月(yyyy年M月 格式,用于版本审查对比)
  17. - ISO 8601 格式(用于机器解析)
  18. - 星期几
  19. 典型调用场景:
  20. 1. 版本审查:判断配风计划的编制月份是否为当月最新版本
  21. 2. 编制时间审查:判断编制时间是否在执行月份的上一个月
  22. 3. 数据时效性判断:判断配风计划中的数据是否需要更新
  23. Returns:
  24. str: 当前日期时间信息,包含多格式时间字符串
  25. """
  26. now = datetime.now(_CHINA_TZ)
  27. weekday_cn = ["一", "二", "三", "四", "五", "六", "日"][now.weekday()]
  28. return (
  29. f"当前系统时间:\n"
  30. f"- 日期时间:{now.strftime('%Y年%m月%d日 %H:%M:%S')}(中国标准时间 CST)\n"
  31. f"- 当前年月:{now.strftime('%Y年%m月')}\n"
  32. f"- 当前月份:{now.month}月\n"
  33. f"- 当前年份:{now.year}年\n"
  34. f"- 星期:周{weekday_cn}\n"
  35. f"- ISO 8601:{now.strftime('%Y-%m-%dT%H:%M:%S+08:00')}"
  36. )