Lunisolar
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)
Metadata
Release files for lunisolar 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lunisolar-0.1.3.tar.gz | 48.7 kB | Without provenance | Details for lunisolar-0.1.3.tar.gz |
Release files / lunisolar-0.1.3.tar.gz
| Download URL | lunisolar-0.1.3.tar.gz |
|---|---|
| Size | 48.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
11be2162910e341749c0f93151ee1a3bbe2a850c1da1e46af1e762ee348e20f4
|
|
BLAKE2b-256 checksum How to use checksums |
77cab2bb9d44593e3c2dcac9a36f942f28718914c224709f1c52639e85ccda50
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for lunisolar 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.