API Reference

LunarConverter — Gregorian↔lunar

MemberReturnsDescription
ToLunar(DateTime)LunarDateGregorian → lunar; throws when out of range
ToSolar(LunarDate)DateTimeLunar → Gregorian; throws for non-existent dates
TryToSolar(LunarDate, out DateTime)boolReturns false (no throw) for non-existent dates
GetLeapMonth(int lunarYear)intLeap month number (e.g. 2 for 2023); 0 when none
MinDate / MaxDateDateTime1901-02-19 to 2101-01-28

LunarDate (readonly struct)

Year / Month (1-12; a leap month shares its predecessor's number) / Day / IsLeapMonth; ToString() returns Chinese ("2023年閏二月十五").

SolarTerms — the 24 solar terms

MemberReturnsDescription
GetYearTerms(int year)IReadOnlyList<SolarTermInfo>All 24 terms in Gregorian-year order (XiaoHan → DongZhi)
GetExactTime(int year, SolarTerm)DateTimeTransition time (Taiwan time, minute precision)
GetCurrentTerm(DateTime)SolarTermInfoGoverning term of a moment
TryGetTermOfDay(DateTime, out SolarTermInfo?)boolWhether the date is a transition day
MinYear / MaxYearint1901 to 2100

SolarTermInfo: Term / ExactTime / ChineseName. The SolarTerm enum is in-year ordered: XiaoHan(0)DongZhi(23).

GanzhiCalendar — the Ganzhi calendar

MemberReturnsDescription
GetYearGanzhi(DateTime, YearBoundary)GanzhiValueYear pillar; default boundary = exact LiChun minute
GetMonthGanzhi(DateTime)GanzhiValueMonth pillar; switches at the 12 "Jie" exact times, five-tigers stems
GetDayGanzhi(DateTime)GanzhiValueDay pillar (civil date, switches at 00:00)
GetHourGanzhi(DateTime)GanzhiValueHour pillar; Zi starts at 23:00, five-rats stems
GetFourPillars(DateTime, YearBoundary)FourPillarsFour pillars; day pillar follows the Bazi 23:00 convention
GetZodiac(DateTime, YearBoundary)ZodiacZodiac; boundary rule identical to the year pillar
GetChineseName(Zodiac)stringChinese zodiac name
MinDate / MaxDateDateTime1901-02-19 to 2100-12-31

GanzhiValue (readonly struct): Stem / Branch / ChineseName (e.g. 甲子). YearBoundary: LiChun (default) / LunarNewYear.

LunarFestivals — lunar festivals

MemberReturnsDescription
TryGetFestival(DateTime, out LunarFestival)boolWhether the date is a festival; leap months never count
GetFestivalDate(int solarYear, LunarFestival)DateTimeThe festival's date within a Gregorian year

LunarFestival: New Year's Eve, Lunar New Year, Lantern, Dragon Boat, Qixi, Ghost, Mid-Autumn, Double Ninth, Laba, DongZhi (solar-term based).

Laba edge case: lunar 12/8 is only 22-23 days before the next New Year, so a Gregorian year may contain two Laba (first returned) or zero (throws InvalidOperationException). E.g. 2022 has two (Jan 10, Dec 30); 2023 has none.

Exception behavior

  • Out-of-range queries → ArgumentOutOfRangeException (the calendar is never extrapolated)
  • ToSolar with a non-existent lunar date → ArgumentOutOfRangeException (use TryToSolar to avoid)
  • GetFestivalDate when the year has no Laba → InvalidOperationException