Skip to main content

Convert the Korean lunar calendar to/from the Gregorian solar calendar (KARI standard).

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

korean_lunar_calendar-0.4.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

korean_lunar_calendar-0.4.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file korean_lunar_calendar-0.4.0.tar.gz.

File metadata

  • Download URL: korean_lunar_calendar-0.4.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for korean_lunar_calendar-0.4.0.tar.gz
Algorithm Hash digest
SHA256 be56f27bc0594fdbbdf7bbe00f504a9f929a31e311bd7d9bb93561b645afade7
MD5 0c7746c5ff38b637b9e5fd41a885f359
BLAKE2b-256 d59f6160e95f3934026194dc7a0b5c78fe5c6e74761830ddea3e9cfc38e3f983

See more details on using hashes here.

File details

Details for the file korean_lunar_calendar-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for korean_lunar_calendar-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c042e20de0bb702add6bec8d0f6da1ea8d3b170838e63846f70420cf341fe4e7
MD5 9c8c5ce9463b657869a7c34734e11151
BLAKE2b-256 c188f56033b09fdca5c8c5e5fc2f3513950a05cd62caa9bd8e6d2750a887c86e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page