Files
ZiPingEightChar/scripts/astro/day_boundary.py
T
moxiaonian d9da4301cd 公众授权版:normal · 1000 次 · 有效期至 2026-12-31
副本编号 LY-20261007-AC63(水印指纹已嵌入)
含 README、.gitignore;排除 .DS_Store / __pycache__ / .pytest_cache
2026-10-07 17:29:52 +08:00

24 lines
616 B
Python

from datetime import datetime, timedelta
ZI_HOUR_START = 23 # 真太阳时 23:00 换日
def resolve_calendar_day(tst: datetime) -> tuple[datetime, dict]:
"""
子初换日:真太阳时 23:00–24: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:
day += timedelta(days=1)
return day, {
"rule": "子初换日@真太阳时23:00",
"is_late_zi": is_late_zi,
"tst_time": tst.strftime("%Y-%m-%d %H:%M:%S"),
}