chinese-lunar-date API - v1.0.5
    Preparing search index...

    Function gregorianToLunar

    Low-level pure functions for calendar conversion. Most users should prefer the ChineseDate value object API. These functions are useful when you need fine-grained control or want to build custom logic on top of the core algorithms.

    • Convert Gregorian date to lunar date

      This is the primary conversion function. It computes the JDE of the given Gregorian date, then determines the corresponding lunar date by finding the enclosing new moon and major solar term.

      For dates in January before the 20th, the Gregorian year is adjusted backward because Chinese New Year never starts before January 20.

      Parameters

      • config: CalendarConfig

        Calendar configuration (determines epoch and timezone)

      • year: number

        Gregorian year (e.g., 2024)

      • month: number

        Month (1-12)

      • day: number

        Day of month

      Returns LunarDateValue

      Lunar date value with cycle/year/month/leap/day

      gregorianToLunar(CHINESE_CONFIG, 2024, 6, 21)
      // { cycle: 78, year: 34, month: 5, leap: false, day: 6 }

      // Using Japanese calendar (different timezone may yield different results)
      gregorianToLunar(JAPANESE_CONFIG, 2024, 6, 21)
      // { cycle: 78, year: 34, month: 5, leap: false, day: 6 }