Skip to main content

A Chinese Calendar Library in Pure Python

Python package PyPI - Version PyPI - Downloads

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
  • 0.1.5: fix bug in ==
  • 0.1.4: support '+', '-' and compare, fix bug in year 2050
  • 0.1.3: support python 3.0

Limits

this library can only deal with year from 1900 to 2099 (in chinese calendar).

See also

Metadata

Release files for lunardate 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lunardate 0.3.1
File Size Uploaded Provenance Actions
lunardate-0.3.1.tar.gz 18.9 kB Without provenance Details for lunardate-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lunardate 0.3.1
File Interpreter ABI Platform Actions
lunardate-0.3.1-py3-none-any.whl Python 3 none any Details for lunardate-0.3.1-py3-none-any.whl

Total release size: 37.9 kB

Release files / lunardate-0.3.1.tar.gz

Download URL lunardate-0.3.1.tar.gz
Size 18.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5ebf790457a22829b7df6b742232d5d38fe7d0daf85683b804131e73a0e06efc
BLAKE2b-256 checksum
How to use checksums
1da0f593b3532992be55d0d97bddc94ddf18123d49359c980dcbcd8822058357
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Release files / lunardate-0.3.1-py3-none-any.whl

Download URL lunardate-0.3.1-py3-none-any.whl
Size 19.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
32eb92dafaff313a8a549a51f2ec59f66eca2a05049fc93f02b7e9743521cb3e
BLAKE2b-256 checksum
How to use checksums
611e720c9667a8a406fa59e8ec5feba579455c5595f743f2493e3c2cc9c64dc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Security for lunardate 0.3.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page