• Converts a given solar (Gregorian) date to a lunar (Chinese) date. The function calculates the corresponding lunar year, month, day, and whether the month is a leap month. If the solar date is invalid or out of range, it returns -1.

    Parameters

    • date: Date

      The solar date to convert. It should be a valid JavaScript Date object.

    Returns LunarDate | -1

    A LunarDate object representing the corresponding lunar date, or -1 if the solar date is invalid.

    // => { year: 2024, month: 2, day: 10, isLeapMonth: false }
    toLunar(new Date('2024-01-01'))
    // => -1
    toLunar(new Date('1900-01-30'))
    // => -1
    toLunar(new Date('2101-01-01'))