Calendar.h header

#include <ew/core/Calendar.h>

Namespace ew::core

Calendar class

class ew::core::Calendar

A project's calendar: an ordered list of months (each with its own length), a cycle of weekday names, and an era label – so fantasy chronologies (custom months, weeks, eras) read naturally. Days use a standard 24-hour clock. Time is stored elsewhere as an absolute instant in minutes since the epoch (year 1, first month, first day, 00:00); this type converts that instant to and from a human date and formats it. A default-constructed Calendar is the familiar 12-month Gregorian year (no leap days) with a 7-day week. Value type; the project owns one and it is persisted with the project metadata.

Members

ew::core::Calendar::Calendar()

Constructs the default Gregorian-style calendar.

const std::vector< CalendarMonth > & ew::core::Calendar::months() const

The calendar's months, in order.

void ew::core::Calendar::setMonths(std::vector< CalendarMonth > months)

Sets the calendar's months.

const std::vector< QString > & ew::core::Calendar::weekdays() const

The weekday names, in order; the first is the weekday of the epoch day.

void ew::core::Calendar::setWeekdays(std::vector< QString > weekdays)

Sets the weekday names.

const QString & ew::core::Calendar::eraName() const

The era label appended when formatting a year (e.g. "CE", "Third Age"). May be empty. Used only when no named eras are defined; the eras list takes precedence when non-empty.

void ew::core::Calendar::setEraName(QString eraName)

Sets the era label.

const std::vector< CalendarEra > & ew::core::Calendar::eras() const

The named eras that partition the year line for a multi-reckoning chronology (BCE/CE style). When non-empty they drive year rendering (formatYear) instead of the single eraName label; when empty, the single label is used. Kept sorted by start year.

void ew::core::Calendar::setEras(std::vector< CalendarEra > eras)

Sets the named eras.

QString ew::core::Calendar::formatYear(qint64 year) const

Renders year with its era: when eras are defined, the era-relative number and label (e.g. "15475 Before Fall", "250 After Fall"); otherwise the raw year with the single eraName label (e.g. "250 CE", "-15474 CE"), or just the number when no era is set.

int ew::core::Calendar::daysPerYear() const

The total number of days in a year (the sum of the month lengths).

CalendarDate ew::core::Calendar::toDate(qint64 minutesSinceEpoch) const

Converts an absolute instant (minutes since the epoch) to a calendar date.

qint64 ew::core::Calendar::toInstant(const CalendarDate &date) const

Converts a calendar date back to an absolute instant (minutes since the epoch).

QString ew::core::Calendar::weekdayName(qint64 minutesSinceEpoch) const

The weekday name for the day containing minutesSinceEpoch, or empty if no weekdays are defined.

QString ew::core::Calendar::format(qint64 minutesSinceEpoch) const

A human-readable rendering of minutesSinceEpoch (e.g. "3 March, Year 1 CE" plus the time of day when it is not midnight).

bool operator==(const Calendar &, const Calendar &)=default

Value equality over all fields (months, weekdays, era), so a no-op calendar edit can be detected before pushing an undoable command.

CalendarDate struct

struct ew::core::CalendarDate

A calendar date broken into its components. Years may be zero or negative (years before the epoch); month and day are 1-based; hour and minute are on a standard 24h/60m clock.

Members

qint64 ew::core::CalendarDate::year = 1

The year (may be zero or negative for years before the epoch).

int ew::core::CalendarDate::month = 1

The 1-based month number.

int ew::core::CalendarDate::day = 1

The 1-based day of the month.

int ew::core::CalendarDate::hour = 0

The hour on a 24-hour clock (0-23).

int ew::core::CalendarDate::minute = 0

The minute of the hour (0-59).

CalendarEra struct

struct ew::core::CalendarEra

One named era in a calendar's reckoning: a label plus the absolute year at which its span begins. Eras partition the year line so a chronicle can read "250 After Fall" or, counting backward toward an epoch, "15475 Before Fall" (BCE/CE style). Stored instants are unaffected – an era changes only how a year is displayed.

Members

QString ew::core::CalendarEra::name

The era's display label (e.g. "After Fall", "Third Age"). When empty, only the number shows.

qint64 ew::core::CalendarEra::startYear = 1

The absolute year (in the calendar's internal numbering, where year 1 is the epoch) at which this era's span begins. Eras are ordered by this, and the earliest era also covers every year below its own start. An ascending era's first year reads "1"; a descending era counts down to "1" at the year just before the next era begins.

bool ew::core::CalendarEra::countsDown = false

Whether the era counts backward toward the next era's start (BCE-style: the year just before the switch is 1, the one before that 2, ...). Ascending (the default) counts up from the era's start. A descending era with no following era falls back to counting up.

bool operator==(const CalendarEra &, const CalendarEra &)=default

Value equality over all fields, so calendars can be compared (e.g. to detect a no-op edit).

CalendarMonth struct

struct ew::core::CalendarMonth

One month in a calendar: its name and how many days it has.

Members

QString ew::core::CalendarMonth::name

The month's display name (e.g. "March", "Harvestmoon").

int ew::core::CalendarMonth::days = 0

The number of days in the month (at least 1 for a well-formed calendar).

bool operator==(const CalendarMonth &, const CalendarMonth &)=default

Value equality over all fields, so calendars can be compared (e.g. to detect a no-op edit).