Skip to main content

纯 Python 中的中国日历库

项目描述

中国日历:http ://en.wikipedia.org/wiki/Chinese_calendar

用法

>>> 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
>>> today = LunarDate.today()
>>> type(today).__name__
'LunarDate'
>>> # support '+' and '-' between datetime.date and datetime.timedelta
>>> ld = LunarDate(1976,8,8)
>>> sd = datetime.date(2008,1,1)
>>> td = datetime.timedelta(days=10)
>>> ld-ld
datetime.timedelta(0)
>>> (ld-sd).days
-11444
>>> ld-td
LunarDate(1976, 7, 27, 0)
>>> (sd-ld).days
11444
>>> ld+td
LunarDate(1976, 8, 18, 0)
>>> td+ld
LunarDate(1976, 8, 18, 0)
>>> ld2 = LunarDate.today()
>>> ld < ld2
True
>>> ld <= ld2
True
>>> ld > ld2
False
>>> ld >= ld2
False
>>> ld == ld2
False
>>> ld != ld2
True
>>> ld == ld
True
>>> LunarDate.today() == LunarDate.today()
True
>>> before_leap_month = LunarDate.fromSolarDate(2088, 5, 17)
>>> before_leap_month.year
2088
>>> before_leap_month.month
4
>>> before_leap_month.day
27
>>> before_leap_month.isLeapMonth
False
>>> leap_month = LunarDate.fromSolarDate(2088, 6, 17)
>>> leap_month.year
2088
>>> leap_month.month
4
>>> leap_month.day
28
>>> leap_month.isLeapMonth
True
>>> after_leap_month = LunarDate.fromSolarDate(2088, 7, 17)
>>> after_leap_month.year
2088
>>> after_leap_month.month
5
>>> after_leap_month.day
29
>>> after_leap_month.isLeapMonth
False

限制

这个库只能处理从 1900 年到 2099 年(中国历)的年份。

也可以看看

  • lunar:http ://packages.qa.debian.org/l/lunar.html ,一个用C写的转换器,这个程序就是从它衍生出来的。

  • python-lunar:http ://code.google.com/p/liblunar/ 另一个用 C 编写的库,包括一个 python 绑定。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

lunardate-0.2.0.tar.gz (5.1 kB 查看哈希

已上传 source

内置发行版

lunardate-0.2.0-py3.7.egg (10.2 kB 查看哈希

已上传 3 7

lunardate-0.2.0-py3-none-any.whl (5.6 kB 查看哈希

已上传 py3

lunardate-0.2.0-py2.7.egg (10.1 kB 查看哈希

已上传 2 7

lunardate-0.2.0-py2-none-any.whl (5.6 kB 查看哈希

已上传 py2