lunardate: Chinese Calendar Library

0.2.2 · active · verified Sat Apr 11

lunardate is a Chinese Calendar Library implemented purely in Python. It provides functionalities to convert between solar and lunar dates, handle leap months, and perform date arithmetic. The library is currently at version 0.2.2 and sees infrequent but consistent updates, with recent fixes and year range extensions.

Warnings

Install

Imports

Quickstart

Demonstrates converting between solar and lunar dates, getting the current lunar date, and checking for leap months.

import datetime
from lunardate import LunarDate

# Convert a solar date to a lunar date
lunar_date = LunarDate.fromSolarDate(1976, 10, 1)
print(f"Lunar Date for 1976-10-01: {lunar_date}")
# Expected: LunarDate(1976, 8, 8, 1) (year, month, day, isLeapMonth)

# Convert a lunar date back to a solar date
solar_date = LunarDate(1976, 8, 8, 1).toSolarDate()
print(f"Solar Date for LunarDate(1976, 8, 8, 1): {solar_date}")
# Expected: 1976-10-01

# Get today's lunar date
today_lunar = LunarDate.today()
print(f"Today's Lunar Date: {today_lunar}")

# Check for leap month in a year
leap_month_2023 = LunarDate.leapMonthForYear(2023)
print(f"Leap month for 2023: {leap_month_2023}") # Expected: 2

leap_month_2022 = LunarDate.leapMonthForYear(2022)
print(f"Leap month for 2022: {leap_month_2022}") # Expected: None

view raw JSON →