Class GregorianCalendar

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ISOCalendar, JulianCalendar

public class GregorianCalendar extends MonthDayYear
Implementation of the proleptic Gregorian calendar. The Gregorian calendar is the internationally accepted civil calendar introduced by Pope Gregory XIII in October 1582. This implementation extends the calendar backwards in time (proleptic) for dates before its actual adoption.

Key features:

  • A year is 365 days, with leap years adding one day
  • Leap year rule: divisible by 4, except centuries not divisible by 400
  • 12 months with varying lengths (28-31 days)
* @version 2.0
Since:
1.0
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
See Also:
  • Field Details

    • MONTHS

      protected static final String[] MONTHS
      Month names in English.
    • EPOCH

      protected static long EPOCH
      The epoch: January 1, 1 CE (Rata Die 1).
  • Constructor Details

    • GregorianCalendar

      public GregorianCalendar(long rataDie)
      Creates a Gregorian calendar set to the specified Rata Die.
      Parameters:
      rataDie - the day number
    • GregorianCalendar

      public GregorianCalendar(int year, int month, int day)
      Creates a Gregorian calendar set to the specified date.
      Parameters:
      year - the year (negative for BCE)
      month - the month (1-12)
      day - the day of month (1-31)
    • GregorianCalendar

      public GregorianCalendar()
      Creates a Gregorian calendar set to the epoch (January 1, 1 CE).
    • GregorianCalendar

      public GregorianCalendar(AlternateCalendar calendar)
      Creates a Gregorian calendar from another calendar's date.
      Parameters:
      calendar - the source calendar
  • Method Details

    • isLeapYear

      public static boolean isLeapYear(int year)
      Determines if the specified year is a leap year in the Gregorian calendar.
      Parameters:
      year - the year to check
      Returns:
      true if it's a leap year
    • recomputeRD

      protected void recomputeRD()
      Recomputes the Rata Die from the current year, month, and day fields.
      Specified by:
      recomputeRD in class AlternateCalendar
    • set

      public void set(long rataDie)
      Sets this calendar to the specified Rata Die and recomputes the date fields.
      Specified by:
      set in class AlternateCalendar
      Parameters:
      rataDie - the new Rata Die value
    • recomputeFromRD

      protected void recomputeFromRD()
      Recomputes the year, month, and day fields from the current Rata Die.
      Specified by:
      recomputeFromRD in class AlternateCalendar
    • dayNumber

      public int dayNumber()
      Returns the day number within the year (1-366).
      Returns:
      the day of year
    • daysLeft

      public int daysLeft()
      Returns the number of days remaining in the year.
      Returns:
      days left until year end
    • getSuffix

      protected String getSuffix()
      Returns the era suffix (e.g., "CE" or "BCE"). Subclasses may override.
      Specified by:
      getSuffix in class MonthDayYear
      Returns:
      an empty string for the standard Gregorian calendar
    • monthName

      protected String monthName()
      Returns the name of the current month.
      Specified by:
      monthName in class MonthDayYear
      Returns:
      the month name
    • getMonths

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

      public String toString()
      Description copied from class: MonthDayYear
      Returns a string representation of this date.
      Overrides:
      toString in class MonthDayYear
      Returns:
      formatted date string