A Chinese Calendar Library in Pure Python
Maintained. Last release 8 days ago, commits in 3 of the last 26 weeks. Weaker on commit activity and release cadence.
$
pip install lunardateA Chinese Calendar Library in Pure Python
Chinese Calendar: http://en.wikipedia.org/wiki/Chinese_calendar
Install
pip install lunardate
Usage
>>> from lunardate import LunarDate
>>> LunarDate.from_solar_date(1976, 10, 1)
LunarDate(1976, 8, 8, 1)
>>> LunarDate(1976, 8, 8, 1).to_solar_date()
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).is_leap_month
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
datetime.timedelta(-11444)
>>> ld-td
LunarDate(1976, 7, 27, 0)
>>> sd-ld
datetime.timedelta(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
>>> LunarDate.leap_month_for_year(2023)
2
>>> LunarDate.leap_month_for_year(2022)
None
News
- 0.3.1: fix month lengths for lunar years 1933, 1954 and 1978; expand CI to Python 3.12-3.14 on ubuntu-24.04
- 0.3.0: drop python 2, add typing hints, rename identifiers to follow PEP 8
- 0.2.2: add LunarDate.leapMonthForYear; fix bug in year 1899
- 0.2.1: fix bug in year 1956
- 0.2.0: extend year to 2099, thanks to @FuGangqiang