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”.

Usage

Initializing a Chinese date:

>>> from lunisolar import ChineseDate
>>> mid_autumn = ChineseDate.from_chinese(chinese_year=2013,
                                          chinese_month=8,
                                          chinese_day=15,
                                          is_leap_month=False)
>>> mid_autumn
chinese_date(year=2013, month=8, day=15, is_leap_month=False)
>>> mid_autumn.gregorian_date
datetime.date(2013, 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 datetime.date:

>>> ChineseDate.today()
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
1969
>>> moon_landing.month
6
>>> moon_landing.day
7
>>> moon_landing.is_leap_month
False
>>> moon_landing.zodiac
rooster
>>> moon_landing.element
earth
>>> moon_landing.heavenly_stem
ji
>>> moon_landing.earthly_branch
you

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

>>> from datetime import timedelta
>>> cdate = ChineseDate.from_gregorian(1969, 7, 20)
>>> gdate = datetime.date(2013, 2, 10)
>>> cdate > gdate
False
>>> gdate - cdate
datetime.timedelta(15911)
>>> 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.

Source Distribution

lunisolar_upgraded-0.1.4.tar.gz (49.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lunisolar_upgraded-0.1.4-py3-none-any.whl (48.8 kB view details)

Uploaded Python 3

File details

Details for the file lunisolar_upgraded-0.1.4.tar.gz.

File metadata

  • Download URL: lunisolar_upgraded-0.1.4.tar.gz
  • Upload date:
  • Size: 49.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.7

File hashes

Hashes for lunisolar_upgraded-0.1.4.tar.gz
Algorithm Hash digest
SHA256 052423c730e3c935ad4befe051330657313c1df8f8caa1bab0169e15f7b75891
MD5 e4834c974d64949a033f996d5db1873b
BLAKE2b-256 fcb5912a099e8be4e70a2d0464135cf2d9d0164d4e8114cfd40ba471ecf30374

See more details on using hashes here.

File details

Details for the file lunisolar_upgraded-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for lunisolar_upgraded-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ea46eb5dc7bbd18c8d4e20d6fe8a5bfe04f3a4ef2d0ec74157062b6ebf97df10
MD5 924e2d2fb6eee83e4d61a491444a557d
BLAKE2b-256 bb4067b5abbfc21e93f21dd5e905c84c4605bd1610e090dc381c7e9686715a1c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page