Skip to content

Add calendar and date/time system#228

Open
The3dVehicleguy wants to merge 4 commits intoPanosK92:masterfrom
The3dVehicleguy:date-time-refactor
Open

Add calendar and date/time system#228
The3dVehicleguy wants to merge 4 commits intoPanosK92:masterfrom
The3dVehicleguy:date-time-refactor

Conversation

@The3dVehicleguy
Copy link

Created a calendar and date/time system for the Spartan, including the ability to create a customizable calendar class and utility methods for date and time calculations. This will allow user-defined calendar systems, supporting features like leap years, custom month and day names, and flexible time calculations. I also exposed calendar functions to Lua scripting.

Note

This pull request is the pretext for my UI refactor progress. These functions will allow me to add to the Spartan editor a more interactive and visual time of day/sun and moon cycle UI.

The most important changes are:

Core Calendar System Implementation:

  • Added a comprehensive Calendar class (Calendar.h, Calendar.cpp) with singleton management, date/time calculation utilities (days in month/year, leap year detection, current date retrieval, etc.), and support for both standard and custom calendars. The implementation includes detailed methods for getting names of months, days, seasons, and day cycles, as well as validation and conversion functions. [1] [2]

Custom Calendar Support:

  • Introduced a CustomCalendar class (CustomCalendar.h, CustomCalendar.cpp) that extends Calendar and allows users to define custom month/day/season names, month lengths, leap year rules, and day cycle names. The class overrides relevant methods to use custom data if provided, falling back to the standard calendar otherwise. [1] [2]

DateTime Utility Enhancements:

  • Implemented the DateTime class (DateTime.cpp) with static methods for getting and setting the time of day, as well as validating time values (hours, minutes, seconds). This provides a simple interface for time-of-day management within the engine.

Extensibility and Safety:

  • Used assertions and input validation throughout the calendar and date/time methods to ensure correct usage and to provide clear error messages for invalid inputs (e.g., invalid month, day, or time values). [1] [2]

- Introduced Calendar, CustomCalendar, and DateTime classes for flexible date/time handling, including leap year logic, custom calendars, and time-of-day management.
- Refactored world time logic to use DateTime.
- Exposed calendar functions to Lua scripting. Improved path normalization and added robust validation and error handling.
Copilot AI review requested due to automatic review settings February 23, 2026 23:08
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a runtime calendar/date-time layer (with custom calendar support) and exposes calendar/time queries to Lua via the World table, enabling editor/UI features that depend on date and time-of-day.

Changes:

  • Introduces Calendar (singleton) with date calculations, naming utilities, and “current date” accessors.
  • Adds CustomCalendar to override month/day/season/day-cycle naming, month lengths, and leap-year rules.
  • Adds DateTime wrapper for time-of-day access and updates World Lua bindings to expose calendar functions.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
source/runtime/World/World.cpp Switches to std::ranges::replace, routes time-of-day through DateTime, and exposes calendar functions to Lua.
source/runtime/World/Time/DateTime.h Declares a small static DateTime API (time-of-day + validation).
source/runtime/World/Time/DateTime.cpp Implements DateTime by delegating to the existing world_time state.
source/runtime/World/Time/Calendar.h Declares the Calendar singleton API and overridable implementation hooks.
source/runtime/World/Time/Calendar.cpp Implements Gregorian-like calendar utilities and “current date” queries.
source/runtime/World/Time/CustomCalendar.h Declares CustomCalendar overrides and customization setters.
source/runtime/World/Time/CustomCalendar.cpp Implements override logic using custom vectors/functions with fallbacks to Calendar.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Move TimeZoneDbEntry definition to headers.
- Convert lookup helpers to TimeZone class static methods.
- Update TimeZone.cpp to use new Find* methods.
- Modernize string handling with std::erase_if and std::ranges::transform.
- Improve modularity and reduce code duplication in DB access.
Copy link
Collaborator

@MrDrElliot MrDrElliot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Just a few small suggestions

The3dVehicleguy added a commit to The3dVehicleguy/SpartanEngine that referenced this pull request Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants