Registry / serialization / zhdate

zhdate

JSON →
library1.0pypypi✓ verified 83d ago

A Python library to convert Chinese Lunar Calendar (农历) to datetime and vice versa. Supports lunar dates from 1900 to 2100. Current version: 1.0. Release cadence is irregular; last release was 2024.

pip install zhdate
INSTALL
IMPORT
SIG · ZHDATE
Z
zhdate
serializationpythonv1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ZhDate
from zhdate import ZhDate

Basic usage: creating ZhDate objects and converting between lunar and Gregorian dates.

from zhdate import ZhDate # Convert Chinese lunar date to Gregorian date lunar_date = ZhDate(2024, 1, 1) # 2024-01-01 in lunar calendar gregorian_date = lunar_date.to_datetime() print(gregorian_date) # Output: 2024-02-10 00:00:00 # Convert Gregorian date to Chinese lunar date gregorian_dt = datetime.date(2024, 2, 10) lunar_date = ZhDate.from_datetime(gregorian_dt) print(lunar_date) # Output: ZhDate(2024, 1, 1) # Leap month example lunar_date_leap = ZhDate(2023, 2, 1, leap_month=True) # Leap second month print(lunar_date_leap.to_datetime())
Debug
Known issues
gotchaZhDate uses 1-indexed months and days (January = 1), unlike some lunar libraries that use 0-indexed.
fix
Always use month=1 for January, day=1 for first day.
affects: all
gotchaLeap months must be explicitly specified with leap_month=True. The library does not auto-detect leap months.
fix
When creating a leap month, pass leap_month=True (e.g., ZhDate(2023, 2, 1, leap_month=True)).
affects: all
deprecatedThe from_datetime method may be renamed or behavior changed in future versions. Check changelog.
fix
Use ZhDate.from_datetime(date_obj) as documented; watch for alternative static methods.
affects: >=1.0
Errors
Common errors & fixes
ValueError: month must be in 1..12
ZhDate expects month 1-12, not 0-11.
fix
Ensure month is between 1 and 12. For example, use month=1 for January.
AttributeError: module 'zhdate' has no attribute 'ZhDate'
Typo or incorrect import (e.g., `import zhdate` then `zhdate.ZhDate` is correct, but some try `zhdate.zhdate`).
fix
Use `from zhdate import ZhDate` or `import zhdate; zhdate.ZhDate`.
Upgrade
Version history
1.0latest on PyPI · released Jan 21, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
70 hits · last 30 days
node
64
OpenAI (training)
1
Resources
zhdate — pip install zhdate · libregistry