Python纯实现的中国农历日期库lunardate

Python

A Chinese Calendar Library in Pure Python Chinese Calendar: http://en.wikipedia.org/wiki/Chinese_calendar Usage >>> from lunardate import LunarDate >>> LunarDate.fromSolarDate(1976, 10, 1) LunarDate(1976, 8, 8, 1) >>> LunarDate(1976, 8, 8, 1).toSolarDate() datetime.date(1976, 10, 1) >>> LunarDate(1976, 8, 8, 1).year 1976 >>> LunarDate(1976, 8, 8, 1).month 8 >>> LunarDate(1976, 8, 8, 1).day 8 >>> LunarDate(1976, 8, 8, 1).isLeapMonth True >>> Limits this library can only deal with year from 1900 to 2050 (in chinese calendar). See also lunar: http://packages.qa.debian.org/l/lunar.html, A converter written in C, this program is derived from it. python-lunar: http://code.google.com/p/liblunar/, Another library written in

详细介绍

资源简介:

lunardate 是一个用纯 Python 实现的中国农历(阴阳历)日期处理库。该库可以在不依赖外部 C 语言扩展或第三方服务的情况下,直接在 Python 环境中完成公历与农历之间的相互转换。

  • 主要功能:
    • 支持将公历日期(阳历)转换为对应的中国农历日期
    • 支持将中国农历日期还原为对应的公历日期
    • 可获取农历年份、月份、日份等详细信息
    • 能够判断某个月份是否为闰月
  • 使用方法简明:
    • 通过 LunarDate.fromSolarDate(年, 月, 日) 方法,将阳历转为农历
    • 通过 LunarDate(年, 月, 日, 是否闰月).toSolarDate() 方法,将农历转回阳历
    • 支持属性访问,如 year、month、day、isLeapMonth 等,方便数据提取和逻辑判断
  • 适用场景:
    • 需要在 Python 项目中处理中国传统节日、黄道吉日等基于农历的时间计算需求
    • 开发与中华文化相关的软件,如日程管理、节气提醒、民俗应用等
    • 教育领域,用于教学演示和科学计算,帮助理解阴阳合历原理及其算法实现
  • 特点与限制:
    • 完全基于 Python 实现,无需额外依赖,易于集成和部署
    • 支持1900年至2050年间的日期换算,覆盖现代常用时间范围
    • 源自权威 C 程序 lunar 的算法移植,保证了换算准确性和可靠性

总结:

lunardate 是一款专注于中国农历与公历互转的小巧实用工具,非常适合对中华传统时间体系有需求的开发者和研究人员。无论是节日提醒还是民俗应用开发,都能提供高效便捷的基础支撑。

📦

确认下载

资源名称

消耗积分