Class AlternateCalendar
java.lang.Object
org.episteme.social.history.calendars.AlternateCalendar
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
MayanCalendar, SevenDaysWeek
Abstract base class for alternate (non-Gregorian) calendar systems.
Provides common operations for calendar date arithmetic, including
conversion to/from Rata Die (RD) and Julian Day (JD) representations.
The Rata Die is a day-counting system where day 1 corresponds to January 1, 1 CE in the proleptic Gregorian calendar.
- Since:
- 1.0
- Version:
- 2.0
- Author:
- Mark E. Shoulson (original implementation), Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic longThe epoch day (Rata Die) for this calendar system's origin.static final doubleThe Julian Day epoch offset.protected longThe current Rata Die (day number) for this calendar instance.static booleanFlag to control Unicode output in toString methods. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new AlternateCalendar set to the epoch date.AlternateCalendar(long rataDie) Creates a new AlternateCalendar set to the specified Rata Die. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(long days) Adds a number of days to this calendar date.static longamod(long dividend, long divisor) Computes the adjusted modulo (1-based instead of 0-based).longdifference(AlternateCalendar other) Calculates the difference in days between this calendar and another.static longdifference(AlternateCalendar cal1, AlternateCalendar cal2) Calculates the difference in days between two calendar dates.static longfloorDiv(long dividend, long divisor) Computes the floor division (rounds toward negative infinity).static longfromJD(double julianDay) Converts a Julian Day number to a Rata Die.booleanisAfter(AlternateCalendar other) Checks if this calendar date is after another calendar date.booleanisBefore(AlternateCalendar other) Checks if this calendar date is before another calendar date.static intmod(long dividend, int divisor) Computes the mathematical modulo (always positive) of a long and an int.static longmod(long dividend, long divisor) Computes the mathematical modulo (always positive) of two long values.protected abstract voidRecomputes the calendar-specific fields from the current Rata Die.protected abstract voidRecomputes the Rata Die from the calendar-specific fields.abstract voidset(long rataDie) Sets this calendar to the specified Rata Die and recomputes the calendar fields.voidsubtract(long days) Subtracts a number of days from this calendar date.doubletoJD()Returns the Julian Day number for this calendar date.static doubletoJD(long rataDie) Converts a Rata Die to a Julian Day number.longtoRD()Returns the Rata Die (day number) for this calendar date.abstract StringtoString()Returns a string representation of this calendar date.
-
Field Details
-
EPOCH
public static long EPOCHThe epoch day (Rata Die) for this calendar system's origin. -
unicode
public static boolean unicodeFlag to control Unicode output in toString methods. -
JD_EPOCH
public static final double JD_EPOCHThe Julian Day epoch offset. JD 0 = November 24, 4714 BCE (proleptic Gregorian). This constant relates RD to JD: JD = RD - JD_EPOCH- See Also:
-
rd
protected long rdThe current Rata Die (day number) for this calendar instance.
-
-
Constructor Details
-
AlternateCalendar
public AlternateCalendar()Creates a new AlternateCalendar set to the epoch date. -
AlternateCalendar
public AlternateCalendar(long rataDie) Creates a new AlternateCalendar set to the specified Rata Die.- Parameters:
rataDie- the Rata Die day number
-
-
Method Details
-
mod
public static long mod(long dividend, long divisor) Computes the mathematical modulo (always positive) of two long values. Unlike Java's % operator, this always returns a non-negative result.- Parameters:
dividend- the dividenddivisor- the divisor- Returns:
- the non-negative remainder
-
mod
public static int mod(long dividend, int divisor) Computes the mathematical modulo (always positive) of a long and an int.- Parameters:
dividend- the dividenddivisor- the divisor- Returns:
- the non-negative remainder
-
amod
public static long amod(long dividend, long divisor) Computes the adjusted modulo (1-based instead of 0-based). Returns values in range [1, divisor] instead of [0, divisor-1].- Parameters:
dividend- the dividenddivisor- the divisor- Returns:
- the 1-based remainder
-
floorDiv
public static long floorDiv(long dividend, long divisor) Computes the floor division (rounds toward negative infinity).- Parameters:
dividend- the dividenddivisor- the divisor- Returns:
- the floor of the quotient
-
set
public abstract void set(long rataDie) Sets this calendar to the specified Rata Die and recomputes the calendar fields.- Parameters:
rataDie- the new Rata Die value
-
toRD
public long toRD()Returns the Rata Die (day number) for this calendar date.- Returns:
- the current Rata Die
-
toJD
public double toJD()Returns the Julian Day number for this calendar date.- Returns:
- the Julian Day
-
toJD
public static double toJD(long rataDie) Converts a Rata Die to a Julian Day number.- Parameters:
rataDie- the Rata Die value- Returns:
- the corresponding Julian Day
-
fromJD
public static long fromJD(double julianDay) Converts a Julian Day number to a Rata Die.- Parameters:
julianDay- the Julian Day value- Returns:
- the corresponding Rata Die
-
isBefore
Checks if this calendar date is before another calendar date.- Parameters:
other- the calendar to compare against- Returns:
- true if this date is before the other date
-
isAfter
Checks if this calendar date is after another calendar date.- Parameters:
other- the calendar to compare against- Returns:
- true if this date is after the other date
-
difference
Calculates the difference in days between two calendar dates.- Parameters:
cal1- the first calendarcal2- the second calendar- Returns:
- the number of days (cal1 - cal2)
-
difference
Calculates the difference in days between this calendar and another.- Parameters:
other- the calendar to compare against- Returns:
- the number of days (this - other)
-
add
public void add(long days) Adds a number of days to this calendar date.- Parameters:
days- the number of days to add (can be negative)
-
subtract
public void subtract(long days) Subtracts a number of days from this calendar date.- Parameters:
days- the number of days to subtract
-
recomputeFromRD
protected abstract void recomputeFromRD()Recomputes the calendar-specific fields from the current Rata Die. Called after setting the RD value. -
recomputeRD
protected abstract void recomputeRD()Recomputes the Rata Die from the calendar-specific fields. Called after setting individual calendar fields. -
toString
-