Class AlternateCalendar

java.lang.Object
org.episteme.social.history.calendars.AlternateCalendar
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
MayanCalendar, SevenDaysWeek

public abstract class AlternateCalendar extends Object implements Serializable
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

    Fields
    Modifier and Type
    Field
    Description
    static long
    The epoch day (Rata Die) for this calendar system's origin.
    static final double
    The Julian Day epoch offset.
    protected long
    The current Rata Die (day number) for this calendar instance.
    static boolean
    Flag to control Unicode output in toString methods.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates 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 Type
    Method
    Description
    void
    add(long days)
    Adds a number of days to this calendar date.
    static long
    amod(long dividend, long divisor)
    Computes the adjusted modulo (1-based instead of 0-based).
    long
    Calculates the difference in days between this calendar and another.
    static long
    Calculates the difference in days between two calendar dates.
    static long
    floorDiv(long dividend, long divisor)
    Computes the floor division (rounds toward negative infinity).
    static long
    fromJD(double julianDay)
    Converts a Julian Day number to a Rata Die.
    boolean
    Checks if this calendar date is after another calendar date.
    boolean
    Checks if this calendar date is before another calendar date.
    static int
    mod(long dividend, int divisor)
    Computes the mathematical modulo (always positive) of a long and an int.
    static long
    mod(long dividend, long divisor)
    Computes the mathematical modulo (always positive) of two long values.
    protected abstract void
    Recomputes the calendar-specific fields from the current Rata Die.
    protected abstract void
    Recomputes the Rata Die from the calendar-specific fields.
    abstract void
    set(long rataDie)
    Sets this calendar to the specified Rata Die and recomputes the calendar fields.
    void
    subtract(long days)
    Subtracts a number of days from this calendar date.
    double
    Returns the Julian Day number for this calendar date.
    static double
    toJD(long rataDie)
    Converts a Rata Die to a Julian Day number.
    long
    Returns the Rata Die (day number) for this calendar date.
    abstract String
    Returns a string representation of this calendar date.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • EPOCH

      public static long EPOCH
      The epoch day (Rata Die) for this calendar system's origin.
    • unicode

      public static boolean unicode
      Flag to control Unicode output in toString methods.
    • JD_EPOCH

      public static final double JD_EPOCH
      The 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 rd
      The 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 dividend
      divisor - 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 dividend
      divisor - 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 dividend
      divisor - 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 dividend
      divisor - 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

      public boolean isBefore(AlternateCalendar other)
      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

      public boolean isAfter(AlternateCalendar other)
      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

      public static long difference(AlternateCalendar cal1, AlternateCalendar cal2)
      Calculates the difference in days between two calendar dates.
      Parameters:
      cal1 - the first calendar
      cal2 - the second calendar
      Returns:
      the number of days (cal1 - cal2)
    • difference

      public long difference(AlternateCalendar other)
      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

      public abstract String toString()
      Returns a string representation of this calendar date.
      Overrides:
      toString in class Object
      Returns:
      a formatted date string