Files
ZiPingEightChar/scripts/astro/day_boundary.py
T
moxiaonian 433c9b4a41 v3.6.0 同步发版
- 交互契约改对话式询问(禁点选工具、一次1~2问、先铺垫再问),规则库 3.6
- 盘面图默认生成+chart_shot 截图;品牌区、大运/流年小卡信息补全、交流群二维码卡
- day_boundary 子正换日;memory_save --update-chart 换盘留痕;share_export 事件简介+城市级地域
- share_push 失败诊断+代理引导;_runtime_guard;修 STAR_ORDER 三奇贵人 KeyError
- README 规则计数 541→542;manifest 重建(1275 文件);测试 142 项全绿
2026-10-10 13:13:41 +08:00

26 lines
822 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
ZI_HOUR_START = 23 # 真太阳时 23:00 换日
def resolve_calendar_day(tst: datetime, rule: str = "子初") -> tuple[datetime, dict]:
"""
日界归算:rule="子初"(默认)真太阳时 23:00–24:00 归入次日;
rule="子正" 以 0:00 为日界,晚子时不换日。
返回
(日历日 00:00 的 datetime, flag)
"""
is_late_zi = tst.hour == ZI_HOUR_START
day = tst.replace(hour=0, minute=0, second=0, microsecond=0)
if is_late_zi and rule != "子正":
day += timedelta(days=1)
return day, {
"rule": ("子正换日@真太阳时00:00" if rule == "子正"
else "子初换日@真太阳时23:00"),
"is_late_zi": is_late_zi,
"tst_time": tst.strftime("%Y-%m-%d %H:%M:%S"),
}