Skip to content

请教:优化 L762 行农历年份解析,解决公历年与农历年不一致问题 #14

@hans599

Description

@hans599

b = "農曆︰{}{}月{}日\n".format(cn2an.transform(str(year)+"年", "an2cn"), an2cn(self.lunar_date_d(year, month, day).get("月")), an2cn(self.lunar_date_d(year,month, day).get("日")))

该语句中,年份的解析式为 cn2an.transform(str(year)+"年", "an2cn")
这会导致公历年年初的日期解析错误:例如 2026 年 1 月的公历日期,实际农历年份应为 二零二五 年,但代码中仍会解析为二零二六 年,与真实农历年份不符。

建议将年份解析逻辑改为从 self.lunar_date_d() 方法返回的农历年取值,例如

# 原行修改:年份从lunar_date_d返回值取,而非传入的year
b = "農曆︰{}{}月{}日\n".format(
    cn2an.transform(str(self.lunar_date_d(year, month, day).get("年"))+"年", "an2cn"),
    an2cn(self.lunar_date_d(year, month, day).get("月")),
    an2cn(self.lunar_date_d(year,month, day).get("日"))
)

非常感谢您开源分享这个实用的工具!以上建议若有不妥之处,还请指正 😊

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions