Skip to main content

A library to handle the Chinese calendar

Project description

Lunisolar is a Python package for handling Chinese calendars. Lunisolar contains a set of helper functions designed to make it easy to convert between the Gregorian (Western) calendar and the Chinese calendar.

Based on the works of Helmer Aslaksen. Built on top of PyCalCal, the Python implementation of Calendrica 3.0, a set of calendar-related algorithms as described in Dershowitz and Reingold’s book “Calendrical Calculations”.


Initializing a Chinese date:

>>> from lunisolar import ChineseDate
>>> mid_autumn = ChineseDate.from_chinese(chinese_year=2013,
>>> mid_autumn
chinese_date(year=2013, month=8, day=15, is_leap_month=False)
>>> mid_autumn.gregorian_date, 9, 19)

A Chinese date object can be initialized from a Gregorian (western) date:

>>> from lunisolar import ChineseDate
>>> moon_landing = ChineseDate.from_gregorian(1969, 7, 20)
>>> moon_landing
chinese_date(year=1969, month=6, day=7, is_leap_month=False)

The ChineseDate class shares the same constructors as

chinese_date(year=2012, month=12, day=29, is_leap_month=False)

>>> timestamp = 1360414893.724195
>>> ChineseDate.fromtimestamp(timestamp)
chinese_date(year=2012, month=12, day=29, is_leap_month=False)

>>> ordinal = 734908
>>> ChineseDate.fromordinal(ordinal)
chinese_date(year=2012, month=12, day=29, is_leap_month=False)

Retrieving properties of the Chinese calendar:

>>> moon_landing = ChineseDate.from_gregorian(1969, 7, 20)
>>> moon_landing.year
>>> moon_landing.month
>>> moon_landing.is_leap_month
>>> moon_landing.zodiac
>>> moon_landing.element
>>> moon_landing.heavenly_stem
>>> moon_landing.earthly_branch

The add, subtract, and comparison operators for ChineseDate is similar to that of the object. For subtraction and comparison, ChineseDate and can be used interchangeably.

>>> from datetime import timedelta
>>> cdate = ChineseDate.from_gregorian(1969, 7, 20)
>>> gdate =, 2, 10)
>>> cdate > gdate
>>> gdate - cdate
>>> diff = timedelta(200)
>>> cdate + diff
chinese_date(year=1969, month=12, day=29, is_leap_month=False)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for lunisolar, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size lunisolar-0.1.3.tar.gz (48.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page