Files
ZiPingEightChar/scripts/astro/day_boundary.py
T
moxiaonian b20fd5c3c9 v3.6.2 同步发版:晚子时不再双重换日、港澳时区归位
- 晚子时(真太阳时 23:00–24:00,约 4% 的盘)修正:换日改由 tyme4py provider 原生实现(cast 新增 sect 参数,1=子初 / 2=子正),排盘层不再自行预滚日。3.6.1 及此前会滚两次,日柱多进一天、时柱随之错干——锚点 1973-08-23 23:32 男:旧 癸巳日壬子时 → 正 壬辰日庚子时。已排过的晚子时盘建议重排核对
- --day-boundary 子正 现真正生效(走 sect=2,晚子时日柱算当天),此前只改审计文案不改实际排盘
- data/cities.json 港澳 28 个条目由 Asia/Shanghai 改为 Asia/Hong_Kong(19)、Asia/Macau(9):大陆 1986–1991 行夏令时而港澳 1979 年后无,沿用上海区会把大陆夏令时错加到港澳命主身上
- 修副本环境 `pytest tests/` 收集期中断(test_sync_tool 模块级加载外层 tools/,skipif 挡不住导入),现按设计整模块 skip
- .gitignore 新增 data/.license.json、data/.update_check.json,本机授权与更新缓存不再可能误入仓
- 测试 178 项全绿(副本内 sync 工具 4 项按设计 skip);manifest 1278 文件,ed25519 签名,公钥指纹 3089bc1cc9a453e5…
2026-10-12 19:05:09 +08:00

30 lines
1.1 KiB
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 为日界,晚子时不换日。
注意:换日的**实际排盘效果**由 chart.tyme_adapter.cast 的 sect 参数
(tyme4py provider)原生实现;本函数返回的日历日仅供审计与外部参考,
调用方不得把它再拼回时刻传给 cast(会双重换日)。
返回
(日历日 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"),
}