summaryrefslogtreecommitdiffstats
path: root/src/corelib/time/qdatetime.h
diff options
context:
space:
mode:
authorSoroush Rabiei <soroush@ametisco.ir>2017-01-14 20:23:31 +0330
committerEdward Welbourne <edward.welbourne@qt.io>2019-08-20 13:41:21 +0200
commitaa8393c94fea01a4806b204fd3aa343a4e90666b (patch)
tree071cf0bd8934b094d4e0208a25c11f439acb8173 /src/corelib/time/qdatetime.h
parent8f083bade0ba33d4be8a2d3ed1b5ce005aab6d8d (diff)
Add support for calendars beside Gregorian
Add QCalendarBackend as a base class for calendar implementations and QCalendar as a facade via which to access it. QDate's implicit implementation of the Gregorian calendar becomes QGregorianCalendar and QDate methods now support choice of calendar. Convert QLocale's CLDR data for month names to a locale-data component of each supported calendar and relevant QLocale methods now support choice of calendar. Adapt Python scripts for locale data generation to extract month name data from CLDR (keeping on version v35.1) into the new calendar-locale files. The locale data for the Gregorian calendar is held in a Roman calendar base, for sharing with other calendars. Add tests for basic uses of the new API. [ChangeLog][QtCore][QCalendar] Added QCalendar to support diverse calendars, supported by implementing QCalendarBackend. [ChangeLog][QtCore][QDate] Allow choice of calendar in various operations, with Gregorian remaining the default. Done-with: Lars Knoll <lars.knoll@qt.io> Done-with: Edward Welbourne <edward.welbourne@qt.io> Fixes: QTBUG-17110 Fixes: QTBUG-950 Change-Id: I9d6278f394269a183aee8156e990cec4d5198ab8 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/corelib/time/qdatetime.h')
-rw-r--r--src/corelib/time/qdatetime.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/corelib/time/qdatetime.h b/src/corelib/time/qdatetime.h
index 89ea4ee24a..e1909b85e3 100644
--- a/src/corelib/time/qdatetime.h
+++ b/src/corelib/time/qdatetime.h
@@ -54,6 +54,7 @@ Q_FORWARD_DECLARE_OBJC_CLASS(NSDate);
QT_BEGIN_NAMESPACE
+class QCalendar;
class QTimeZone;
class QDateTime;
@@ -69,6 +70,7 @@ private:
public:
Q_DECL_CONSTEXPR QDate() : jd(nullJd()) {}
QDate(int y, int m, int d);
+ QDate(int y, int m, int d, QCalendar cal);
Q_DECL_CONSTEXPR bool isNull() const { return !isValid(); }
Q_DECL_CONSTEXPR bool isValid() const { return jd >= minJd() && jd <= maxJd(); }
@@ -82,6 +84,14 @@ public:
int daysInYear() const;
int weekNumber(int *yearNum = nullptr) const;
+ int year(QCalendar cal) const;
+ int month(QCalendar cal) const;
+ int day(QCalendar cal) const;
+ int dayOfWeek(QCalendar cal) const;
+ int dayOfYear(QCalendar cal) const;
+ int daysInMonth(QCalendar cal) const;
+ int daysInYear(QCalendar cal) const;
+
QDateTime startOfDay(Qt::TimeSpec spec = Qt::LocalTime, int offsetSeconds = 0) const;
QDateTime endOfDay(Qt::TimeSpec spec = Qt::LocalTime, int offsetSeconds = 0) const;
#if QT_CONFIG(timezone)
@@ -103,8 +113,12 @@ public:
QString toString(Qt::DateFormat f = Qt::TextDate) const;
#if QT_STRINGVIEW_LEVEL < 2
QString toString(const QString &format) const;
+ QString toString(const QString &format, QCalendar cal) const;
#endif
+
QString toString(QStringView format) const;
+ QString toString(Qt::DateFormat f, QCalendar cal) const;
+ QString toString(QStringView format, QCalendar cal) const;
#endif
#if QT_DEPRECATED_SINCE(5,0)
QT_DEPRECATED_X("Use setDate() instead") inline bool setYMD(int y, int m, int d)
@@ -112,6 +126,7 @@ public:
#endif
bool setDate(int year, int month, int day);
+ bool setDate(int year, int month, int day, QCalendar cal);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void getDate(int *year, int *month, int *day); // ### Qt 6: remove
@@ -121,6 +136,8 @@ public:
Q_REQUIRED_RESULT QDate addDays(qint64 days) const;
Q_REQUIRED_RESULT QDate addMonths(int months) const;
Q_REQUIRED_RESULT QDate addYears(int years) const;
+ Q_REQUIRED_RESULT QDate addMonths(int months, QCalendar cal) const;
+ Q_REQUIRED_RESULT QDate addYears(int years, QCalendar cal) const;
qint64 daysTo(const QDate &) const;
Q_DECL_CONSTEXPR bool operator==(const QDate &other) const { return jd == other.jd; }
@@ -134,6 +151,7 @@ public:
#if QT_CONFIG(datestring)
static QDate fromString(const QString &s, Qt::DateFormat f = Qt::TextDate);
static QDate fromString(const QString &s, const QString &format);
+ static QDate fromString(const QString &s, const QString &format, QCalendar cal);
#endif
static bool isValid(int y, int m, int d);
static bool isLeapYear(int year);
@@ -353,6 +371,7 @@ public:
#if QT_CONFIG(datestring)
static QDateTime fromString(const QString &s, Qt::DateFormat f = Qt::TextDate);
static QDateTime fromString(const QString &s, const QString &format);
+ static QDateTime fromString(const QString &s, const QString &format, QCalendar cal);
#endif
#if QT_DEPRECATED_SINCE(5, 8)