Skip to main content

LunarCalendar: A Lunar-Solar Converter

Last stable version (PyPI)

Overview

If you aren’t familiar with English, can read Chinese(中文) here.

LunarCalendar is a Lunar-Solar Converter, containing a number of lunar and solar holidays in China.

Korean and Japanese lunar calendar is the same as Chinese calendar, but has different holidays. If LunarCalendar is extended, Korean and Japanese holidays are easily included, with their languages.

LunarCalendar supports the time range 1900-2100. But if you have a need for the time range, you can use generate.html to extend it.

LunarCalendar is inspired by Lunar-Solar-Calendar-Converter.

Features

  • Accurate raw data, synchronize with Microsolf’s ChineseLunisolarCalendar class

  • Easy to extend holidays and languages

  • included Lunar Festivals, such as: MidAutumn Festival, Chinese New Year Eve, DragonBoat Festivals

  • included Solar Festivals without fixed dates, such as: Mother’s Day, Easter

  • Added legality check of the lunar and solar date

Install

LunarCalendar can be installed from the PyPI with easy_install:

$ easy_install LunarCalendar

Or pip:

$ pip install LunarCalendar

Console Commands

A console command called lunar-find can be used to find the date of the festival, using it’s chinese name. Default to this year. Supporting alias of the festival.

$ lunar-find 重阳
重阳节 on 2018: 2018-10-17

$ lunar-find 登高节 2019
重阳节 on 2019: 2019-10-07

Quickstart

Solar to Lunar:

import datetime
from lunarcalendar import Converter, Solar, Lunar, DateNotExist

solar = Solar(2018, 1, 1)
print(solar)
lunar = Converter.Solar2Lunar(solar)
print(lunar)
solar = Converter.Lunar2Solar(lunar)
print(solar)
print(solar.to_date(), type(solar.to_date()))

Lunar to Solar:

lunar = Lunar(2018, 2, 30, isleap=False)
print(lunar)
solar = Converter.Lunar2Solar(lunar)
print(solar)
lunar = Converter.Solar2Lunar(solar)
print(lunar)
print(lunar.to_date(), type(lunar.to_date()))
print(Lunar.from_date(datetime.date(2018, 4, 15)))

Legality check for solar and lunar date. 2018-2-15(Leap Month) does not exist, but 2012-4-4(Leap Month) exists:

Lunar(2012, 4, 4, isleap=True)  # date(2012, 5, 24)
try:
    lunar = Lunar(2018, 2, 15, isleap=True)
except DateNotExist:
    print(traceback.format_exc())

Print all the festivals included, with Chinese and English. Other languages are welcome to extend(Fork & Pull Request).

from lunarcalendar.festival import festivals

# print festivals, using English or Chinese
print("----- print all festivals on 2018 in chinese: -----")
for fest in festivals:
    print(fest.get_lang('zh'), fest(2018))

print("----- print all festivals on 2017 in english: -----")
for fest in festivals:
    print(fest.get_lang('en'), fest(2017))

Output:

......
母亲节 2018-05-13
父亲节 2018-06-17
中秋节 2018-09-24
感恩节 2018-11-22
重阳节 2018-10-17
春节 2018-02-16
中元节 2018-08-25
七夕节 2018-08-17
腊八节 2019-01-13
清明节 2018-04-05
除夕 2019-02-04
寒衣节 2018-11-08
元宵节 2018-03-02
龙抬头 2018-03-18
端午节 2018-06-18
......

Contribution

Including festival standards:

  • Common holidays in the the country, such as: Christmas, Halloween, etc.

  • Lunar holidays.

  • Solar holidays without fixed dates, such as: Mother’s Day, Easter, etc.

Supporting Chinese and English only now. If you want to add Korean or Japanese supports, modify lunarcalendar/festival.py to add holidays and languages.

Some unusual holidays may not be included, welcom to extend.

About

Metadata

Release files for LunarCalendar 0.0.7

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

Source distribution (sdist)

Source distribution for LunarCalendar 0.0.7
File Size Uploaded Provenance Actions
LunarCalendar-0.0.7.tar.gz 11.2 kB Without provenance Details for LunarCalendar-0.0.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for LunarCalendar 0.0.7
File Interpreter ABI Platform Actions
LunarCalendar-0.0.7-py2.py3-none-any.whl Python 3, Python 2 none any Details for LunarCalendar-0.0.7-py2.py3-none-any.whl

Total release size: 22.6 kB

Release files / LunarCalendar-0.0.7.tar.gz

Download URL LunarCalendar-0.0.7.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
94f91d42e8b1300787f0a807041b5c8612443070248a670236a992042a73753f
BLAKE2b-256 checksum
How to use checksums
25b8c5f77c0970efa20611d2df869bab2b18c81f5829a9ad6cfe0660ee27f294
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / LunarCalendar-0.0.7-py2.py3-none-any.whl

Download URL LunarCalendar-0.0.7-py2.py3-none-any.whl
Size 11.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
6eb2e36a736e697cee476a8394ee306f36a8f2766d85d8f023ca31922a9c5611
BLAKE2b-256 checksum
How to use checksums
9ef3f898419f3b47484261cf004b3253ed9997f1b08078d495ea243de83eca1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for LunarCalendar 0.0.7

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