Skip to content

Calendar System

CalendarSystem converts elapsed canonical days into dates. Use Gregorian mode for familiar dates or a CalendarDefinition for worlds with their own months, weeks, and leap rules. Changing display-clock hours does not redefine a calendar day.

Configure a calendar

  1. Use an initialized context with an enabled Time System and Calendar System.
  2. In the Calendar System Inspector choose Calendar: Gregorian or Custom.
  3. In Custom mode assign Calendar Definition. Create one with Assets > Create > Sital > Tunal > Calendar, preferably in a project-owned folder.
  4. Configure Starting Date for simulated time, then Date Transition in real-time seconds (default component value 1).
  5. Enter Play Mode and inspect the current date. Advance time across midnight to check that clock and date change together.

Gregorian system-clock mode uses the operating-system date; Starting Date is not used. A custom calendar under system time anchors its configured date and advances with elapsed real-world days. Manual date transitions are disabled while a system clock is authoritative.

Author a Calendar Definition

Each normal month has a name, at least one day, and nonnegative extra leap days. Configure day names, the first weekday index, and whether weekday counting is continuous or resets according to the selected reset rule. The calendar asset Inspector exposes validation; resolve it before assigning the definition.

Leap-year rule chooses the years: None, Interval, Gregorian, or Cycle. Interval uses a positive interval and first leap year. Cycle uses a positive cycle length and selected years within that cycle. The Gregorian rule includes the century exception and 400-year correction.

Leap-year structure chooses the change: None, AddDays, AppendMonths, InsertMonths, or ReplaceMonths. AddDays uses each month's leap-day count; month-list structures use the leap-month list. Insertion index 0 means before the first normal month. A date valid in a normal year may not have the same month structure in a leap year.

Date units and boundaries

DateData stores day, month, year; its constructor takes day, month, year, not year first. Month and day numbers are one-based. Gregorian representability follows DateTime dates (years 1–9999). Custom dates must pass the active definition's validation; do not assume Gregorian limits or a valid year zero. Use IsValidDate and CanRepresentElapsedDay rather than relying on overflow or wraparound.

// Requires an initialized Gregorian CalendarSystem in Simulated mode.
var target = new Sital.Tunal.Data.DateData(21, 6, 2026);
if (context.Calendar.IsValidDate(target))
    context.Calendar.SetDate(target, 0f); // immediate, preserving time of day

SetDate(date) uses the configured duration; its overload accepts seconds. It converts to a Time System transition, so large moves can snap under the time transition pace limit. Earlier targets rewind. Invalid dates, unavailable initialization, and system-clock mode do not apply a requested manual date.

Runtime integration

Read CurrentDate, CurrentMonthName, CurrentDayOfWeekName, MonthProgress, YearProgress, and ContinuousYearProgress instead of reconstructing the calendar from clock hours. onDateChanged supplies DateData; month/year events supply the current integer month/year. These are state notifications, not an audit trail of every intermediate date in a jump.

SetCalendar(definition) switches to Custom configuration and can rebase the date/elapsed-day relationship; SetGregorian() switches the mode. Neither is merely a text-format toggle. After changing Time System mode through code, call RefreshAfterTimeModeChange() to reconcile the calendar. Test mode changes with downstream systems in your integration.

Related: Time, Astronomy, Profiles.