bazi.calendar.backend¶
历法后端的选择与解析。
CalendarBackend 列出后端身份;calendar_utils_of 返回对应的历法换算实现。
- class bazi.calendar.backend.CalendarBackend(*values)[源代码]¶
命盘进行历法换算(公历 <-> 农历 <-> 干支、节气时刻等)所使用的历法后端。
HKO:基于香港天文台数据,精度到日,没有节气准确时刻。
CELESTIAL:基于
celestial-calendar天文算法,节气时刻精度到秒。CELESTIAL_ALGO2:采用 celestial-calendar 的第二套阴历算法。199 个支持年份中有 6 年与 CELESTIAL 不同;CELESTIAL 贴合香港天文台官方历书,应优先选用。
阴历算法是后端身份的一部分,而非其上的开关;原因见
celestial_utils。参见 https://github.com/0xf3cd/bazi/issues/2 和 https://github.com/0xf3cd/bazi/issues/6。
- static from_str(s: str) CalendarBackend[源代码]¶
从字符串解析历法后端(大小写不敏感)。成员名和值都可以,例如 'HKO' 和 'hko'。
Args:
s: (str) 待解析字符串;没有匹配后端时抛
ValueError。
- bazi.calendar.backend.calendar_utils_of(backend: CalendarBackend | str) CalendarUtilsProtocol[源代码]¶
把历法后端声明解析成实际的历法工具(懒加载),解析结果遵循
CalendarUtilsProtocol。