SLCalendarGregorian.sleela
calendar/src/SLCalendarGregorian.sleela · 109 line(s) · sleela
<< calendar/src/SLCalendarGregorian.sleela
SLeeLa Calendar System.
Definition: the Gregorian calendar (Pope Gregory XIII, 1582) — the single
structural exception to the Julian baseline. Same frame as Julian, with a
refined 4/100/400 leap rule. See calendar/02-gregorian-reform.md. >>
#sleela 2.5
material;
<< Family: calendar. SLCalendarGregorian implements the Gregorian leap rule and
the matching serial-day arithmetic. Applied proleptically (projected before
1582), it is the civil calendar of the Unified Calendar and the United States
System of Integration. Month is 1..12, day is 1..31. >>
class SLCalendarGregorian {
<< The Gregorian leap rule: divisible by 4, except centuries, except centuries
divisible by 400. Average year length is 365.2425 days. >>
boolean isLeapYear(int year) {
if ((year % 400) == 0) { return true; }
if ((year % 100) == 0) { return false; }
if ((year % 4) == 0) { return true; }
return false;
}
<< Days in a given month of a given year (month 1..12). >>
int daysInMonth(int year, int month) {
if (month == 2) {
if (isLeapYear(year)) { return 29; }
return 28;
}
if (month == 4) { return 30; }
if (month == 6) { return 30; }
if (month == 9) { return 30; }
if (month == 11) { return 30; }
return 31;
}
<< Days in a given year: 366 in a leap year, else 365. >>
int daysInYear(int year) {
if (isLeapYear(year)) { return 366; }
return 365;
}
<< Serial day number for a proleptic Gregorian date, sharing the epoch used by
SLCalendarJulian.toSerial() so the two can be differenced directly. >>
int toSerial(int year, int month, int day) {
int y = year;
int m = month;
if (m <= 2) {
y = y - 1;
m = m + 12;
}
int monthDays = ((153 * (m - 3)) + 2) / 5;
<< Gregorian leap-day count: 4/100/400 correction >>
int leapDays = (y / 4) - (y / 100) + (y / 400);
return (y * 365) + leapDays + monthDays + (day - 1);
}
<< Day of week for a proleptic Gregorian date: 0 = Sunday .. 6 = Saturday.
The weekday cycle was never broken by any reform, so this is exact. >>
int dayOfWeek(int year, int month, int day) {
int serial = toSerial(year, month, day);
<< anchor: serial for 2000-01-01 which was a Saturday (weekday 6) >>
int anchorSerial = toSerial(2000, 1, 1);
int diff = serial - anchorSerial;
int w = (6 + diff) % 7;
if (w < 0) { w = w + 7; }
return w;
}
<< ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >>
<< Eleven catalogued attributes with getter/setter pairs. Values faithful to
the real origin. >>
String metaVersion = "1.0.0";
int metaId = 2;
String metaAuthor = "Pope Gregory XIII / Aloysius Lilius / Christopher Clavius";
String metaDate = "2026-11-07";
String metaCopyright = "Public domain (historical calendar)";
String metaTrademark = "none";
String metaCorporation = "mearvk LLC";
String metaOrigin = "International";
String metaBirthDate = "1582";
< maturity/robustness on a 1..10 scale >
int metaScienceRating = 10;
String metaNationalSchedule = "Inter gravissimas (papal bull, 1582)";
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; }
}