Skip to main content

korean_lunar_calendar

Convert between the Korean lunar calendar (음력) and the Gregorian solar calendar (양력) — entirely offline, following the KARI (Korea Astronomy and Space Science Institute) standard.

PyPI version MIT license Zero dependencies Live demo

The Korean and Chinese lunar calendars share the same astronomical basis but can fall on different dates. This library uses the Korean (KARI) standard.

Features

  • Two-way conversion — solar → lunar and lunar → solar.
  • Offline — the conversion table is bundled; no network calls, no external services.
  • GapJa (간지) strings — the sexagenary year/month/day in both Korean (정유년 병오월) and Chinese (丁酉年 丙午月).
  • Leap-month aware — handles intercalation months (윤달) and the 1582 Gregorian reform gap.
  • Input validation — every setter returns a bool; out-of-range, non-integer, and impossible-leap-month dates are rejected.
  • Pure standard library — no third-party dependencies.

Supported range

Calendar From To
Lunar (음력) 1000-01-01 2050-11-18
Solar (양력) 1000-02-13 2050-12-31

Dates outside this range cause the corresponding setter to return False.

Install

pip install korean_lunar_calendar
from korean_lunar_calendar import KoreanLunarCalendar

Usage

Solar → Lunar (양력 → 음력)

calendar = KoreanLunarCalendar()

# setSolarDate(year, month, day) -> bool
calendar.setSolarDate(2017, 6, 24)

print(calendar.LunarIsoFormat())        # 2017-05-01 Intercalation
print(calendar.getGapJaString())        # 정유년 병오월 임오일 (윤월)
print(calendar.getChineseGapJaString()) # 丁酉年 丙午月 壬午日 (閏月)

Lunar → Solar (음력 → 양력)

calendar = KoreanLunarCalendar()

# setLunarDate(year, month, day, isIntercalation) -> bool
calendar.setLunarDate(1956, 1, 21, False)

print(calendar.SolarIsoFormat())  # 1956-03-03
print(calendar.getGapJaString())  # 병신년 경인월 기사일

# Intercalation (leap) month, e.g. lunar 1727-03-01 (leap) -> solar 1727-04-21
calendar.setLunarDate(1727, 3, 1, True)
print(calendar.SolarIsoFormat())  # 1727-04-21
print(calendar.getGapJaString())  # 정미년 갑진월 정사일 (윤월)

Always check the return value of setSolarDate / setLunarDate before reading the result — the accessors reflect the last successful set call.

API

KoreanLunarCalendar() creates a stateful converter. Set a date, then read it back in the other calendar.

Member Returns Description
setSolarDate(year, month, day) bool Set a Gregorian date. Returns False for out-of-range, non-integer, or nonexistent dates.
setLunarDate(year, month, day, isIntercalation) bool Set a lunar date. isIntercalation requests the leap month; returns False if that month has no leap month.
LunarIsoFormat() str Lunar date as YYYY-MM-DD, with Intercalation appended for a leap month.
SolarIsoFormat() str Solar date as YYYY-MM-DD.
getGapJaString() str Sexagenary cycle in Korean, e.g. 정유년 병오월 임오일 (윤월).
getChineseGapJaString() str Sexagenary cycle in Chinese characters, e.g. 丁酉年 丙午月 壬午日 (閏月).

After a successful set you can also read the components directly: lunarYear, lunarMonth, lunarDay, isIntercalation, solarYear, solarMonth, solarDay.

Validation

Every setter validates its input and returns a bool, so you can branch on the result:

calendar = KoreanLunarCalendar()

# Rejected -> returns False
calendar.setLunarDate(99, 1, 1, False)    # before supported range
calendar.setSolarDate(2051, 1, 1)         # after supported range
calendar.setSolarDate(2017, 6, 24.5)      # non-integer input
calendar.setSolarDate(1582, 10, 8)        # skipped by the 1582 Gregorian reform
calendar.setLunarDate(2017, 3, 1, True)   # month 3 of 2017 has no leap month

# Accepted -> returns True
calendar.setLunarDate(1000, 1, 1, False)
calendar.setSolarDate(2050, 12, 31)

Tests

python -m unittest -v

Other languages

Acknowledgements

Conversion data follows the KARI (Korea Astronomy and Space Science Institute) Korean lunar–solar standard. Many thanks to KARI for publishing the reference tables.

License

MIT © Jinil Lee

Release files for korean-lunar-calendar 0.4.0

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

Source distribution (sdist)

Source distribution for korean-lunar-calendar 0.4.0
File Size Uploaded
korean_lunar_calendar-0.4.0.tar.gz 13.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for korean-lunar-calendar 0.4.0
File Interpreter ABI Platform
korean_lunar_calendar-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.7 kB

Release files / korean_lunar_calendar-0.4.0.tar.gz

Download URL korean_lunar_calendar-0.4.0.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
be56f27bc0594fdbbdf7bbe00f504a9f929a31e311bd7d9bb93561b645afade7
BLAKE2b-256 checksum
How to use checksums
d59f6160e95f3934026194dc7a0b5c78fe5c6e74761830ddea3e9cfc38e3f983
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release files / korean_lunar_calendar-0.4.0-py3-none-any.whl

Download URL korean_lunar_calendar-0.4.0-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c042e20de0bb702add6bec8d0f6da1ea8d3b170838e63846f70420cf341fe4e7
BLAKE2b-256 checksum
How to use checksums
c188f56033b09fdca5c8c5e5fc2f3513950a05cd62caa9bd8e6d2750a887c86e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.1

2 release files

0.2.1

2 release files

0.2.0

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

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