|
cxWidgets 1.0
|
Enables easy management of dates. C++17-enhanced version of the original 'date' class. More...
#include <cxDate.h>

Public Member Functions | |
| cxDate (eDateFormats pDateFormat=YYYY_MM_DD, char pSepChar='-') | |
| cxDate (int pYear, int pMonth, int pDay, eDateFormats pDateFormat=YYYY_MM_DD, char pSepChar='-') noexcept | |
| cxDate (std::string_view pDateStr, eDateFormats pDateFormat=YYYY_MM_DD, char pSepChar='-') | |
| cxDate (std::string_view pDateStr, char pSepChar) | |
| cxDate (long pJulianDate, eDateFormats pDateFormat=YYYY_MM_DD, char pSepChar='-') noexcept | |
| virtual | ~cxDate ()=default |
| cxDate (const cxDate &)=default | |
| cxDate & | operator= (const cxDate &)=default |
| int | getYear () const noexcept |
| int | getMonth () const noexcept |
| int | getDay () const noexcept |
| eDateFormats | getDateFormat () const noexcept |
| char | getSepChar () const noexcept |
| bool | getDisplayLong () const noexcept |
| void | setYear (int pYear) noexcept |
| void | setMonth (int pMonth) noexcept |
| void | setDay (int pDay) noexcept |
| void | setDateFormat (eDateFormats pDateFormat) noexcept |
| void | setSepChar (char pSepChar) noexcept |
| void | setDisplayLong (bool pDisplay) noexcept |
| bool | setDate (int pYear, int pMonth, int pDay) noexcept |
| void | addYears (int pNumYears) noexcept |
| void | subtractYears (int pNumYears) noexcept |
| void | addMonths (int pNumMonths) noexcept |
| void | subtractMonths (int pNumMonths) noexcept |
| void | addDays (int pNumDays) noexcept |
| void | subtractDays (int pNumDays) noexcept |
| void | operator+= (int pNumDays) noexcept |
| void | operator-= (int pNumDays) noexcept |
| bool | operator== (const cxDate &pThat) const noexcept |
| bool | operator!= (const cxDate &pThat) const noexcept |
| bool | operator> (const cxDate &pThat) const noexcept |
| bool | operator>= (const cxDate &pThat) const noexcept |
| bool | operator< (const cxDate &pThat) const noexcept |
| bool | operator<= (const cxDate &pThat) const noexcept |
| cxDate | operator++ (int) noexcept |
| cxDate & | operator++ () noexcept |
| cxDate | operator-- (int) noexcept |
| cxDate & | operator-- () noexcept |
| cxDate | operator+ (int pNumDays) const noexcept |
| cxDate | operator- (int pNumDays) const noexcept |
| int | operator- (const cxDate &pThat) const noexcept |
| std::string | toString () const |
| bool | fromString (std::string_view pDateStr) |
| int | numMonthDays () const noexcept |
| bool | isLeapYear () const noexcept |
| eWeekDays | dayOfWeek () const noexcept |
| std::string | dayOfWeekStr () const |
| long | toJulian () const noexcept |
| void | fromJulian (long pJulianDate) noexcept |
Static Public Member Functions | |
| static int | numMonthDays (int pMonth, int pYear) noexcept |
| static bool | isLeapYear (int pYear) noexcept |
| static eWeekDays | dayOfWeek (int pYear, int pMonth, int pDay) noexcept |
| static std::string | dayOfWeekStr (eWeekDays pWeekDay) |
| static std::string | dayOfWeekStr (int pYear, int pMonth, int pDay) |
| static std::string | monthName (int pMonth, bool pAbbreviated=false) |
| static std::string | getToday (bool pLong=false) |
| static int | getCurrentYear () noexcept |
| static cxDate | today () noexcept |
| static std::optional< cxDate > | tryParse (std::string_view pDateStr, eDateFormats pDateFormat=YYYY_MM_DD, char pSepChar='-') |
| static long | toJulian (int pYear, int pMonth, int pDay) noexcept |
| static void | fromJulian (long pJulianDate, int &pYear, int &pMonth, int &pDay) noexcept |
| static eDateFormats | getDateFormat (std::string_view pDateStr) |
| static std::string | getDateFormatStr (eDateFormats pDateFormat) |
| static void | monthCalendar (int pYear, int pMonth, std::ostream &pOutStream=std::cout, int pTrailingEndlines=2) |
| static void | yearCalendar (int pYear, std::ostream &pOutStream=std::cout, int pTrailingEndlines=2) |
Friends | |
| std::ostream & | operator<< (std::ostream &pOS, const cxDate &pDate) |
| std::istream & | operator>> (std::istream &pIS, cxDate &pDate) |
Enables easy management of dates. C++17-enhanced version of the original 'date' class.
Note: Months and days are 1-based (months 1-12, days 1-31). Julian date calculations assume noon for time of day, so Julian dates are whole numbers.
|
explicit |
Default constructor - initializes to today's date.
|
noexcept |
Constructor with explicit year, month, day.
| cx::cxDate::cxDate | ( | std::string_view | pDateStr, |
| eDateFormats | pDateFormat = YYYY_MM_DD, |
||
| char | pSepChar = '-' |
||
| ) |
Constructor from a date string (e.g. "2026-03-16").
References fromString().
| cx::cxDate::cxDate | ( | std::string_view | pDateStr, |
| char | pSepChar | ||
| ) |
Constructor from a date string with auto-detected format.
References fromString(), getDateFormat(), and cx::UNKNOWN.
|
noexcept |
Constructor from a Julian date number.
|
virtualdefault |
|
default |
|
noexcept |
Adds pNumDays days to the date.
References cx::CXDATE_END_MONTH, cx::CXDATE_START_DAY, and cx::CXDATE_START_MONTH.
Referenced by operator+(), operator++(), and test_Arithmetic().
|
noexcept |
Adds pNumMonths months to the date, adjusting the year as needed.
References cx::CXDATE_END_MONTH, cx::CXDATE_MONTHS_IN_YEAR, and cx::CXDATE_START_MONTH.
Referenced by test_Arithmetic().
|
noexcept |
Adds pNumYears years to the date.
|
noexcept |
References dayOfWeek().
Referenced by dayOfWeek(), dayOfWeekStr(), dayOfWeekStr(), and monthCalendar().
|
staticnoexcept |
| string cx::cxDate::dayOfWeekStr | ( | ) | const |
References dayOfWeek(), and dayOfWeekStr().
Referenced by dayOfWeekStr(), dayOfWeekStr(), and cx::operator<<().
|
static |
pWeekDay as a string (e.g. "Monday"). References cx::eFRIDAY, cx::eMONDAY, cx::eSATURDAY, cx::eSUNDAY, cx::eTHURSDAY, cx::eTUESDAY, and cx::eWEDNESDAY.
|
static |
References dayOfWeek(), and dayOfWeekStr().
|
noexcept |
Sets this date from a Julian day number.
|
staticnoexcept |
Converts pJulianDate to year/month/day components.
| bool cx::cxDate::fromString | ( | std::string_view | pDateStr | ) |
Parses pDateStr and updates this date.
References cx::CXDATE_DEFAULT_YEAR, cx::CXDATE_YEAR_2DIGIT_LAST_CENT, cx::DD_MM_YY, cx::DD_MM_YYYY, cx::DDMMYY, cx::DDMMYYYY, cx::MM_DD_YY, cx::MM_DD_YYYY, cx::MMDDYY, cx::MMDDYYYY, cx::YY_MM_DD, cx::YYMMDD, cx::YYYY_MM_DD, and cx::YYYYMMDD.
Referenced by cxDate(), cxDate(), cx::operator>>(), and tryParse().
|
staticnoexcept |
|
inlinenoexcept |
Referenced by cxDate().
|
static |
pDateStr, or UNKNOWN. References cx::DD_MM_YY, cx::DD_MM_YYYY, cx::DDMMYY, cx::MM_DD_YY, cx::MM_DD_YYYY, cx::MMDDYY, cx::UNKNOWN, cx::YYYY_MM_DD, and cx::YYYYMMDD.
|
static |
pDateFormat. References cx::DD_MM_YY, cx::DD_MM_YYYY, cx::DDMMYY, cx::DDMMYYYY, cx::MM_DD_YY, cx::MM_DD_YYYY, cx::MMDDYY, cx::MMDDYYYY, cx::YY_MM_DD, cx::YYMMDD, cx::YYYY_MM_DD, and cx::YYYYMMDD.
|
inlinenoexcept |
Referenced by cx::cxDatePicker::cxDatePicker(), cx::cxDatePicker::setDate(), test_Arithmetic(), and test_Constructors().
|
inlinenoexcept |
|
inlinenoexcept |
Referenced by cx::cxDatePicker::setDate(), cx::cxDatePicker::showModal(), test_Arithmetic(), and test_Constructors().
|
inlinenoexcept |
|
static |
Returns today's date as "YYYY-MM-DD", or in long format if pLong=true.
References setDisplayLong(), and toString().
|
inlinenoexcept |
Referenced by cx::cxDatePicker::showModal(), test_Arithmetic(), and test_Constructors().
|
noexcept |
References isLeapYear().
Referenced by isLeapYear().
|
staticnoexcept |
pYear is a leap year.
|
static |
Prints a one-month calendar to pOutStream.
| pTrailingEndlines | Number of blank lines printed after the calendar. |
References dayOfWeek(), monthName(), and numMonthDays().
Referenced by yearCalendar().
|
static |
pMonth (1–12). | pAbbreviated | If true, returns a 3-letter abbreviation. |
Referenced by monthCalendar(), cx::cxDatePicker::setDate(), and cx::cxDatePicker::showModal().
|
noexcept |
References numMonthDays().
Referenced by monthCalendar(), and numMonthDays().
|
staticnoexcept |
pMonth of pYear, accounting for leap years. References cx::CXDATE_DEFAULT_YEAR, and cx::CXDATE_YEAR_2DIGIT_LAST_CENT.
|
noexcept |
pThat.
|
noexcept |
pNumDays days after this date. References addDays().
|
noexcept |
|
noexcept |
Adds pNumDays days in-place.
|
noexcept |
pThat.
|
noexcept |
pNumDays days before this date. References subtractDays().
|
noexcept |
References subtractDays().
|
noexcept |
|
noexcept |
Subtracts pNumDays days in-place.
|
noexcept |
pThat.
|
noexcept |
pThat.
|
noexcept |
pThat.
|
noexcept |
pThat.
|
noexcept |
pThat.
|
noexcept |
Sets year, month, and day simultaneously.
Referenced by cx::cxDatePicker::cxDatePicker().
|
noexcept |
Sets the date format used by toString() and stream output.
References cx::UNKNOWN.
|
noexcept |
Sets the day-of-month component, clamped to the valid range for the current month.
|
inlinenoexcept |
Enables or disables long human-readable date output.
Referenced by getToday().
|
noexcept |
Sets the month component, clamped to [1, 12].
|
inlinenoexcept |
Sets the separator character used in formatted date strings.
|
noexcept |
Sets the year component, clamped to [CXDATE_YEAR_MIN, CXDATE_YEAR_MAX].
|
noexcept |
Subtracts pNumDays days from the date.
Referenced by operator-(), operator--(), and test_Arithmetic().
|
noexcept |
Subtracts pNumMonths months from the date, adjusting the year as needed.
|
noexcept |
Subtracts pNumYears years from the date.
|
staticnoexcept |
C++17 addition: returns today's date as a cxDate object. More expressive than the string-based getToday().
Referenced by cx::cxDatePicker::cxDatePicker().
|
noexcept |
|
staticnoexcept |
| string cx::cxDate::toString | ( | ) | const |
Referenced by cxDatePickerTest(), and getToday().
|
static |
C++17 addition: tries to parse a date string, returning an std::optional<cxDate> so the caller can check success without exceptions or sentinel values.
References fromString().
|
static |
Prints a full-year calendar to pOutStream.
| pTrailingEndlines | Number of blank lines printed after the calendar. |
References monthCalendar().
|
friend |
Writes the formatted date to pOS.
|
friend |
Reads a formatted date from pIS.