Class ChineseCalendar

All Implemented Interfaces:
Serializable

public class ChineseCalendar extends MonthDayYear
Implementation of the traditional Chinese lunisolar calendar. The Chinese calendar is one of the oldest chronological systems still in use, incorporating both astronomical observations and traditional cultural cycles.

Key features:

  • Epoch: February 15, 2636 BCE
  • Uses a 60-year cycle (Sexagenary cycle) combining Heavenly Stems and Earthly Branches
  • Months are lunar, beginning with the new moon
  • Uses astronomical calculations for new moons and solar terms
  • Leap months are intercalated to align with the solar year
  • Year names combine celestial stem and terrestrial branch (e.g., "Jia-Zi")
* @version 2.0
Since:
1.0
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
See Also:
  • Field Details

    • MONTHS

      public static final String[] MONTHS
      List of Chinese solar terms corresponding to months.
    • EPOCH

      public static final long EPOCH
      The RD number for the Chinese calendar epoch (February 15, 2636 BCE).
    • EPOCHYEAR

      public static final int EPOCHYEAR
      The year of the epoch relative to CE.
      See Also:
  • Constructor Details

    • ChineseCalendar

      public ChineseCalendar(long l)
      Creates a new ChineseCalendar object.
      Parameters:
      l - the Rata Die number.
    • ChineseCalendar

      public ChineseCalendar(int i, int j, int k, boolean flag, int l)
      Creates a new ChineseCalendar object.
      Parameters:
      i - the cycle number.
      j - the year in cycle (1-60).
      k - the month (1-12).
      flag - true if leap month.
      l - the day (1-30).
    • ChineseCalendar

      public ChineseCalendar()
      Creates a new ChineseCalendar object.
  • Method Details

    • majorSolarTerm

      public static int majorSolarTerm(long l)
      Returns the major solar term (Zhongqi) for the given date.
      Parameters:
      l - the Rata Die number.
      Returns:
      the major solar term (1-12).
    • timeZone

      public static double timeZone(long l)
      Returns the time zone offset in minutes for the given RD. Beijing time (UTC+8) is used since 1929.
      Parameters:
      l - the Rata Die number.
      Returns:
      the time zone offset in minutes.
    • timeZone

      public double timeZone()
      Returns the time zone offset for the current RD.
      Returns:
      the time zone offset.
    • dateNextSolarLongitude

      public static long dateNextSolarLongitude(double d, int i)
      Finds the date of the next time the sun reacher a specific longitude.
      Parameters:
      d - the starting RD.
      i - the longitude increment (typically 30).
      Returns:
      the RD of the event.
    • majorSolarTermOnOrAfter

      public static long majorSolarTermOnOrAfter(double d)
      Returns the RD of the next major solar term (Zhongqi) on or after the date.
      Parameters:
      d - the starting RD.
      Returns:
      the RD of the next major solar term.
    • newMoonOnOrAfter

      public static long newMoonOnOrAfter(long l)
      Returns the RD of the next new moon on or after the given RD.
      Parameters:
      l - the starting RD.
      Returns:
      the RD of the next new moon.
    • newMoonBefore

      public static long newMoonBefore(long l)
      Returns the RD of the last new moon before the given RD.
      Parameters:
      l - the starting RD.
      Returns:
      the RD of the previous new moon.
    • noMajorSolarTerm

      public static boolean noMajorSolarTerm(long l)
      Determines if a month (defined by its starting RD) contains no major solar term.
      Parameters:
      l - the starting RD of the lunar month.
      Returns:
      true if the month has no major solar term.
    • priorLeapMonth

      public static boolean priorLeapMonth(long l, long l1)
      Determines if there is a leap month between two dates.
      Parameters:
      l - the starting RD.
      l1 - the ending RD.
      Returns:
      true if a leap month exists in the range.
    • recomputeFromRD

      public void recomputeFromRD()
      Recomputes the cycle, year, month, day, and leap status from the current Rata Die.
      Specified by:
      recomputeFromRD in class AlternateCalendar
    • newYear

      public static long newYear(int i)
      Finds the Rata Die of the Chinese New Year for a given Gregorian year.
      Parameters:
      i - the Gregorian year.
      Returns:
      the RD of the Chinese New Year.
    • recomputeRD

      public void recomputeRD()
      Recomputes the Rata Die number from current Chinese date components.
      Specified by:
      recomputeRD in class AlternateCalendar
    • set

      public void set(long l)
      Sets the Rata Die number and recomputes the date fields.
      Specified by:
      set in class AlternateCalendar
      Parameters:
      l - the Rata Die number.
    • set

      public void set(int i, int j, int k)
      Sets the month, day, and year (combined from cycle and year-in-cycle).
      Overrides:
      set in class MonthDayYear
      Parameters:
      i - the month.
      j - the day.
      k - the year.
    • set

      public void set(int i, int j, int k, boolean flag, int l)
      Sets the cycle, year-in-cycle, month, leap status, and day.
      Parameters:
      i - the cycle.
      j - the year in cycle (1-60).
      k - the month.
      flag - true if leap month.
      l - the day.
    • getLeap

      public boolean getLeap()
      Returns the leap month status of the current date.
      Returns:
      true if it is a leap month.
    • getSuffix

      public String getSuffix()
      Returns the suffix for Chinese years (empty).
      Specified by:
      getSuffix in class MonthDayYear
      Returns:
      an empty string.
    • monthName

      public String monthName()
      Returns the name of the current lunar month, including leap status.
      Specified by:
      monthName in class MonthDayYear
      Returns:
      the month name string.
    • getMonths

      public Enumeration<String> getMonths()
      Returns an enumeration of all Chinese month names.
      Specified by:
      getMonths in class MonthDayYear
      Returns:
      enumeration of month names.
    • toString

      public String toString()
      Returns a string representation of the Chinese date.
      Overrides:
      toString in class MonthDayYear
      Returns:
      the date string.
    • main

      public static void main(String[] args)
      Main method for testing the Chinese calendar implementation.
      Parameters:
      args - command line arguments.