Home /Modules/calendar/SLCalendarConverter.sleela

SLCalendarConverter.sleela

calendar/src/SLCalendarConverter.sleela · 87 line(s) · sleela

<< calendar/src/SLCalendarConverter.sleela
   SLeeLa Calendar System.
   Definition: the Old Style / New Style (Julian <-> Gregorian) converter. The
   day offset between the two calendars is a function of the date, which is why
   national adoptions dropped 10 days in 1582, 11 in 1752, and 13 in 1918.
   See calendar/02, 04, 06. >>
#sleela 2.5
material;

<< Family: calendar. SLCalendarConverter composes a Julian and a Gregorian
   reckoner and reports the O.S./N.S. day offset for any date by differencing
   their shared-epoch serial-day numbers. It also names the known historical
   adoption skips used throughout the calendar documents. >>
class SLCalendarConverter {

  SLCalendarJulian julian;
  SLCalendarGregorian gregorian;

  << Prepare the converter. Call before using any conversion method. >>
  void create() {
    julian = new SLCalendarJulian();
    gregorian = new SLCalendarGregorian();
  }

  << How many days the Julian (Old Style) date label lags behind the Gregorian
     (New Style) one for the given year. Closed form for the Julian-vs-Gregorian
     divergence: floor(y/100) - floor(y/400) - 2. The calendars agreed in the
     2nd/3rd century (the -2), then diverge by one day at each century that is
     not a multiple of 400. Gives 10 in 1582, 11 in 1752, 13 in 1918. >>
  int offsetForDate(int year, int month, int day) {
    if (gregorian == null) { create(); }
    int centuries = year / 100;
    int fourHundreds = year / 400;
    return (centuries - fourHundreds) - 2;
  }

  << Given a Julian (Old Style) date, return the Gregorian (New Style) serial
     day number for the same instant. >>
  int oldStyleToNewSerial(int year, int month, int day) {
    if (julian == null) { create(); }
    return julian.toSerial(year, month, day);
  }

  << The documented one-time deletion at each historical adoption, in days.
     These match calendar/02, 04, 05, 06. >>
  int skipPortugal1582() { return 10; }
  int skipBritishColonies1752() { return 11; }
  int skipRussia1918() { return 13; }

  << ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >>
  String metaVersion = "1.0.0";
  int metaId = 3;
  String metaAuthor = "mearvk LLC Calendar Team";
  String metaDate = "2026-11-07";
  String metaCopyright = "(c) 2026 mearvk LLC";
  String metaTrademark = "none";
  String metaCorporation = "mearvk LLC";
  String metaOrigin = "International";
  String metaBirthDate = "2026";
  < maturity/robustness on a 1..10 scale >
  int metaScienceRating = 9;
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }
  String getAuthor() { return metaAuthor; }
  void setAuthor(String v) { metaAuthor = v; }
  String getDate() { return metaDate; }
  void setDate(String v) { metaDate = v; }
  String getCopyright() { return metaCopyright; }
  void setCopyright(String v) { metaCopyright = v; }
  String getTrademark() { return metaTrademark; }
  void setTrademark(String v) { metaTrademark = v; }
  String getCorporation() { return metaCorporation; }
  void setCorporation(String v) { metaCorporation = v; }
  String getOrigin() { return metaOrigin; }
  void setOrigin(String v) { metaOrigin = v; }
  String getBirthDate() { return metaBirthDate; }
  void setBirthDate(String v) { metaBirthDate = v; }
  int getScienceRating() { return metaScienceRating; }
  void setScienceRating(int v) { metaScienceRating = v; }
  String getNationalSchedule() { return metaNationalSchedule; }
  void setNationalSchedule(String v) { metaNationalSchedule = v; }
}