Class GregorianCalendar
java.lang.Object
org.episteme.social.history.calendars.AlternateCalendar
org.episteme.social.history.calendars.SevenDaysWeek
org.episteme.social.history.calendars.MonthDayYear
org.episteme.social.history.calendars.GregorianCalendar
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
ISOCalendar, JulianCalendar
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)
- Since:
- 1.0
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static longThe epoch: January 1, 1 CE (Rata Die 1).protected static final String[]Month names in English.Fields inherited from class MonthDayYear
day, month, yearFields inherited from class SevenDaysWeek
DAY_NAMES, FRIDAY, MONDAY, SATURDAY, SUNDAY, THURSDAY, TUESDAY, WEDNESDAYFields inherited from class AlternateCalendar
JD_EPOCH, rd, unicode -
Constructor Summary
ConstructorsConstructorDescriptionCreates a Gregorian calendar set to the epoch (January 1, 1 CE).GregorianCalendar(int year, int month, int day) Creates a Gregorian calendar set to the specified date.GregorianCalendar(long rataDie) Creates a Gregorian calendar set to the specified Rata Die.GregorianCalendar(AlternateCalendar calendar) Creates a Gregorian calendar from another calendar's date. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the day number within the year (1-366).intdaysLeft()Returns the number of days remaining in the year.Returns an enumeration of month names.protected StringReturns the era suffix (e.g., "CE" or "BCE").static booleanisLeapYear(int year) Determines if the specified year is a leap year in the Gregorian calendar.protected StringReturns the name of the current month.protected voidRecomputes the year, month, and day fields from the current Rata Die.protected voidRecomputes the Rata Die from the current year, month, and day fields.voidset(long rataDie) Sets this calendar to the specified Rata Die and recomputes the date fields.toString()Returns a string representation of this date.Methods inherited from class MonthDayYear
getDay, getMonth, getYear, setMethods inherited from class SevenDaysWeek
kDayAfter, kDayBefore, kDayNearest, kDayOnOrAfter, kDayOnOrBefore, nthKDay, weekDay, weekDayNameMethods inherited from class AlternateCalendar
add, amod, difference, difference, floorDiv, fromJD, isAfter, isBefore, mod, mod, subtract, toJD, toJD, toRD
-
Field Details
-
MONTHS
Month names in English. -
EPOCH
protected static long EPOCHThe 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
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:
recomputeRDin classAlternateCalendar
-
set
public void set(long rataDie) Sets this calendar to the specified Rata Die and recomputes the date fields.- Specified by:
setin classAlternateCalendar- 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:
recomputeFromRDin classAlternateCalendar
-
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
Returns the era suffix (e.g., "CE" or "BCE"). Subclasses may override.- Specified by:
getSuffixin classMonthDayYear- Returns:
- an empty string for the standard Gregorian calendar
-
monthName
Returns the name of the current month.- Specified by:
monthNamein classMonthDayYear- Returns:
- the month name
-
getMonths
Returns an enumeration of month names.- Specified by:
getMonthsin classMonthDayYear- Returns:
- month names enumeration
-
toString
Description copied from class:MonthDayYearReturns a string representation of this date.- Overrides:
toStringin classMonthDayYear- Returns:
- formatted date string
-