CalendarDateParse.h header

#include <ew/app/CalendarDateParse.h>

Namespace ew::app

CalendarDateParse struct

struct ew::app::CalendarDateParse

The result of reading a date a user typed: the date, and whether it could be understood at all.

Members

ew::core::CalendarDate ew::app::CalendarDateParse::date

The parsed date; meaningful only when ok is true.

bool ew::app::CalendarDateParse::ok = false

True when text could be understood as a date in the calendar.

Functions

CalendarDateParse ew::app::parseCalendarDate(const ew::core::Calendar &calendar, const QString &text)

Reads text as a date in calendar – the inverse Calendar::format never had.

This exists because of TL-08: dates are entered in the same calendar they are displayed in. A user looking at "25 Harvestmoon 1250 SA" must be able to type that back, so the parser accepts every shape the app itself renders, and the obvious shorthands: 1250 -> the year's first instant 1250 SA -> the era is accepted and ignored (it is not a datum) -200 SA -> years before the epoch; the ruler really does show these Harvestmoon 1250 -> the month's first day 25 Harvestmoon 1250 -> what the ruler renders 25 Harvestmoon, Year 1250 SA -> what Calendar::format renders 25 Harvestmoon 1250, 14:30 -> with a time of day

Month names match case-insensitively, by full name or by any prefix that is unambiguous within this calendar – "Harvest" is Harvestmoon when nothing else starts that way, and is rejected when two months do, because guessing between a user's months is worse than asking again.

Returns ok = false rather than a nearby guess when the text cannot be understood, when a month is unknown or ambiguous, or when a day falls outside the length of the month named – a date picker that silently rounds an impossible date is how a writer ends up with a lie in their timeline.