Warning, file /include/QtCore/qdatetime.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005 #ifndef QDATETIME_H
0006 #define QDATETIME_H
0007
0008 #include <QtCore/qcalendar.h>
0009 #include <QtCore/qcompare.h>
0010 #include <QtCore/qlocale.h>
0011 #include <QtCore/qnamespace.h>
0012 #include <QtCore/qshareddata.h>
0013 #include <QtCore/qstring.h>
0014
0015 #include <limits>
0016 #include <chrono>
0017
0018 #if defined(Q_OS_DARWIN) || defined(Q_QDOC)
0019 Q_FORWARD_DECLARE_CF_TYPE(CFDate);
0020 Q_FORWARD_DECLARE_OBJC_CLASS(NSDate);
0021 #endif
0022
0023 QT_BEGIN_NAMESPACE
0024
0025 class QTimeZone;
0026 class QDateTime;
0027
0028 class Q_CORE_EXPORT QDate
0029 {
0030 explicit constexpr QDate(qint64 julianDay) : jd(julianDay) {}
0031 public:
0032 constexpr QDate() : jd(nullJd()) {}
0033 QDate(int y, int m, int d);
0034 QDate(int y, int m, int d, QCalendar cal);
0035
0036 #if (__cpp_lib_chrono >= 201907L && !defined(Q_OS_INTEGRITY)) || defined(Q_QDOC)
0037 QT_POST_CXX17_API_IN_EXPORTED_CLASS
0038 Q_IMPLICIT constexpr QDate(std::chrono::year_month_day date) noexcept
0039 : jd(date.ok() ? stdSysDaysToJulianDay(date) : nullJd())
0040 {}
0041
0042 QT_POST_CXX17_API_IN_EXPORTED_CLASS
0043 Q_IMPLICIT constexpr QDate(std::chrono::year_month_day_last date) noexcept
0044 : jd(date.ok() ? stdSysDaysToJulianDay(date) : nullJd())
0045 {}
0046
0047 QT_POST_CXX17_API_IN_EXPORTED_CLASS
0048 Q_IMPLICIT constexpr QDate(std::chrono::year_month_weekday date) noexcept
0049 : jd(date.ok() ? stdSysDaysToJulianDay(date) : nullJd())
0050 {}
0051
0052 QT_POST_CXX17_API_IN_EXPORTED_CLASS
0053 Q_IMPLICIT constexpr QDate(std::chrono::year_month_weekday_last date) noexcept
0054 : jd(date.ok() ? stdSysDaysToJulianDay(date) : nullJd())
0055 {}
0056
0057 QT_POST_CXX17_API_IN_EXPORTED_CLASS
0058 static constexpr QDate fromStdSysDays(const std::chrono::sys_days &days) noexcept
0059 {
0060 return QDate(stdSysDaysToJulianDay(days));
0061 }
0062
0063 QT_POST_CXX17_API_IN_EXPORTED_CLASS
0064 constexpr std::chrono::sys_days toStdSysDays() const noexcept
0065 {
0066 const qint64 days = isValid() ? jd - unixEpochJd() : 0;
0067 return std::chrono::sys_days(std::chrono::days(days));
0068 }
0069 #endif
0070
0071 constexpr bool isNull() const { return !isValid(); }
0072 constexpr bool isValid() const { return jd >= minJd() && jd <= maxJd(); }
0073
0074
0075 int year() const;
0076 int month() const;
0077 int day() const;
0078 int dayOfWeek() const;
0079 int dayOfYear() const;
0080 int daysInMonth() const;
0081 int daysInYear() const;
0082 int weekNumber(int *yearNum = nullptr) const;
0083
0084 int year(QCalendar cal) const;
0085 int month(QCalendar cal) const;
0086 int day(QCalendar cal) const;
0087 int dayOfWeek(QCalendar cal) const;
0088 int dayOfYear(QCalendar cal) const;
0089 int daysInMonth(QCalendar cal) const;
0090 int daysInYear(QCalendar cal) const;
0091
0092 #if QT_DEPRECATED_SINCE(6, 9)
0093 QT_DEPRECATED_VERSION_X_6_9("Pass QTimeZone instead")
0094 QDateTime startOfDay(Qt::TimeSpec spec, int offsetSeconds = 0) const;
0095 QT_DEPRECATED_VERSION_X_6_9("Pass QTimeZone instead")
0096 QDateTime endOfDay(Qt::TimeSpec spec, int offsetSeconds = 0) const;
0097 #endif
0098
0099 QDateTime startOfDay(const QTimeZone &zone) const;
0100 QDateTime endOfDay(const QTimeZone &zone) const;
0101 QDateTime startOfDay() const;
0102 QDateTime endOfDay() const;
0103
0104 #if QT_CONFIG(datestring)
0105 QString toString(Qt::DateFormat format = Qt::TextDate) const;
0106 QString toString(const QString &format) const;
0107 QString toString(const QString &format, QCalendar cal) const
0108 { return toString(qToStringViewIgnoringNull(format), cal); }
0109 QString toString(QStringView format) const;
0110 QString toString(QStringView format, QCalendar cal) const;
0111 #endif
0112 bool setDate(int year, int month, int day);
0113 bool setDate(int year, int month, int day, QCalendar cal);
0114
0115 void getDate(int *year, int *month, int *day) const;
0116
0117 [[nodiscard]] QDate addDays(qint64 days) const;
0118
0119 #if (__cpp_lib_chrono >= 201907L && !defined(Q_OS_INTEGRITY)) || defined(Q_QDOC)
0120 QT_POST_CXX17_API_IN_EXPORTED_CLASS
0121 [[nodiscard]] QDate addDuration(std::chrono::days days) const
0122 {
0123 return addDays(days.count());
0124 }
0125 #endif
0126
0127 [[nodiscard]] QDate addMonths(int months) const;
0128 [[nodiscard]] QDate addYears(int years) const;
0129 [[nodiscard]] QDate addMonths(int months, QCalendar cal) const;
0130 [[nodiscard]] QDate addYears(int years, QCalendar cal) const;
0131 qint64 daysTo(QDate d) const;
0132
0133 static QDate currentDate();
0134 #if QT_CONFIG(datestring)
0135
0136 static QDate fromString(QStringView string, Qt::DateFormat format = Qt::TextDate);
0137 static QDate fromString(const QString &string, Qt::DateFormat format = Qt::TextDate)
0138 { return fromString(qToStringViewIgnoringNull(string), format); }
0139
0140
0141 static QDate fromString(QStringView string, QStringView format, QCalendar cal)
0142 { return fromString(string.toString(), format, QLocale::DefaultTwoDigitBaseYear, cal); }
0143 QT_CORE_INLINE_SINCE(6, 7)
0144 static QDate fromString(const QString &string, QStringView format, QCalendar cal);
0145 static QDate fromString(const QString &string, const QString &format, QCalendar cal)
0146 { return fromString(string, qToStringViewIgnoringNull(format), QLocale::DefaultTwoDigitBaseYear, cal); }
0147
0148
0149
0150 static QDate fromString(QStringView string, QStringView format,
0151 int baseYear = QLocale::DefaultTwoDigitBaseYear)
0152 { return fromString(string.toString(), format, baseYear); }
0153 static QDate fromString(QStringView string, QStringView format,
0154 int baseYear, QCalendar cal)
0155 { return fromString(string.toString(), format, baseYear, cal); }
0156 static QDate fromString(const QString &string, QStringView format,
0157 int baseYear = QLocale::DefaultTwoDigitBaseYear);
0158 static QDate fromString(const QString &string, QStringView format,
0159 int baseYear, QCalendar cal);
0160 static QDate fromString(const QString &string, const QString &format,
0161 int baseYear = QLocale::DefaultTwoDigitBaseYear)
0162 { return fromString(string, qToStringViewIgnoringNull(format), baseYear); }
0163 static QDate fromString(const QString &string, const QString &format,
0164 int baseYear, QCalendar cal)
0165 { return fromString(string, qToStringViewIgnoringNull(format), baseYear, cal); }
0166 #endif
0167 static bool isValid(int y, int m, int d);
0168 static bool isLeapYear(int year);
0169
0170 static constexpr inline QDate fromJulianDay(qint64 jd_)
0171 { return jd_ >= minJd() && jd_ <= maxJd() ? QDate(jd_) : QDate() ; }
0172 constexpr inline qint64 toJulianDay() const { return jd; }
0173
0174 private:
0175
0176 static constexpr inline qint64 nullJd() { return (std::numeric_limits<qint64>::min)(); }
0177 static constexpr inline qint64 minJd() { return Q_INT64_C(-784350574879); }
0178 static constexpr inline qint64 maxJd() { return Q_INT64_C( 784354017364); }
0179 static constexpr inline qint64 unixEpochJd() { return Q_INT64_C(2440588); }
0180
0181
0182 #if __cpp_lib_chrono >= 201907L && !defined(Q_OS_INTEGRITY)
0183 #if !QT_CORE_REMOVED_SINCE(6, 7)
0184 QT_POST_CXX17_API_IN_EXPORTED_CLASS
0185 #endif
0186 static constexpr qint64
0187 stdSysDaysToJulianDay(const std::chrono::sys_days &days) noexcept
0188 {
0189 const auto epochDays = days.time_since_epoch().count();
0190
0191 if constexpr (sizeof(epochDays) * CHAR_BIT >= 41) {
0192 constexpr auto top = maxJd() - unixEpochJd();
0193 constexpr auto bottom = minJd() - unixEpochJd();
0194 if (epochDays > top || epochDays < bottom)
0195 return nullJd();
0196 }
0197 return unixEpochJd() + epochDays;
0198 }
0199 #endif
0200
0201 qint64 jd;
0202
0203 friend class QDateTime;
0204 friend class QDateTimeParser;
0205 friend class QDateTimePrivate;
0206
0207 friend constexpr bool comparesEqual(const QDate &lhs, const QDate &rhs) noexcept
0208 { return lhs.jd == rhs.jd; }
0209 friend constexpr Qt::strong_ordering
0210 compareThreeWay(const QDate &lhs, const QDate &rhs) noexcept
0211 { return Qt::compareThreeWay(lhs.jd, rhs.jd); }
0212 Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QDate)
0213
0214 #ifndef QT_NO_DATASTREAM
0215 friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, QDate);
0216 friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QDate &);
0217 #endif
0218 };
0219 Q_DECLARE_TYPEINFO(QDate, Q_RELOCATABLE_TYPE);
0220
0221 class Q_CORE_EXPORT QTime
0222 {
0223 explicit constexpr QTime(int ms) : mds(ms)
0224 {}
0225 public:
0226 constexpr QTime(): mds(NullTime)
0227 {}
0228 QTime(int h, int m, int s = 0, int ms = 0);
0229
0230 constexpr bool isNull() const { return mds == NullTime; }
0231 bool isValid() const;
0232
0233 int hour() const;
0234 int minute() const;
0235 int second() const;
0236 int msec() const;
0237 #if QT_CONFIG(datestring)
0238 QString toString(Qt::DateFormat f = Qt::TextDate) const;
0239 QString toString(const QString &format) const
0240 { return toString(qToStringViewIgnoringNull(format)); }
0241 QString toString(QStringView format) const;
0242 #endif
0243 bool setHMS(int h, int m, int s, int ms = 0);
0244
0245 [[nodiscard]] QTime addSecs(int secs) const;
0246 int secsTo(QTime t) const;
0247 [[nodiscard]] QTime addMSecs(int ms) const;
0248 int msecsTo(QTime t) const;
0249
0250 static constexpr inline QTime fromMSecsSinceStartOfDay(int msecs) { return QTime(msecs); }
0251 constexpr inline int msecsSinceStartOfDay() const { return mds == NullTime ? 0 : mds; }
0252
0253 static QTime currentTime();
0254 #if QT_CONFIG(datestring)
0255 static QTime fromString(QStringView string, Qt::DateFormat format = Qt::TextDate);
0256 static QTime fromString(QStringView string, QStringView format)
0257 { return fromString(string.toString(), format); }
0258 static QTime fromString(const QString &string, QStringView format);
0259 static QTime fromString(const QString &string, Qt::DateFormat format = Qt::TextDate)
0260 { return fromString(qToStringViewIgnoringNull(string), format); }
0261 static QTime fromString(const QString &string, const QString &format)
0262 { return fromString(string, qToStringViewIgnoringNull(format)); }
0263 #endif
0264 static bool isValid(int h, int m, int s, int ms = 0);
0265
0266 private:
0267 enum TimeFlag { NullTime = -1 };
0268 constexpr inline int ds() const { return mds == -1 ? 0 : mds; }
0269 int mds;
0270
0271 friend constexpr bool comparesEqual(const QTime &lhs, const QTime &rhs) noexcept
0272 { return lhs.mds == rhs.mds; }
0273 friend constexpr Qt::strong_ordering
0274 compareThreeWay(const QTime &lhs, const QTime &rhs) noexcept
0275 { return Qt::compareThreeWay(lhs.mds, rhs.mds); }
0276 Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QTime)
0277
0278 friend class QDateTime;
0279 friend class QDateTimePrivate;
0280 #ifndef QT_NO_DATASTREAM
0281 friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, QTime);
0282 friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QTime &);
0283 #endif
0284 };
0285 Q_DECLARE_TYPEINFO(QTime, Q_RELOCATABLE_TYPE);
0286
0287 class QDateTimePrivate;
0288
0289 class Q_CORE_EXPORT QDateTime
0290 {
0291 struct ShortData {
0292 #if QT_VERSION >= QT_VERSION_CHECK(7,0,0) || defined(QT_BOOTSTRAPPED)
0293 # if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
0294 qint64 status : 8;
0295 # endif
0296 qint64 msecs : 56;
0297
0298 # if Q_BYTE_ORDER == Q_BIG_ENDIAN
0299 qint64 status : 8;
0300 # endif
0301 #else
0302 # if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
0303 quintptr status : 8;
0304 # endif
0305
0306 qintptr msecs : sizeof(void *) * 8 - 8;
0307
0308 # if Q_BYTE_ORDER == Q_BIG_ENDIAN
0309 quintptr status : 8;
0310 # endif
0311 #endif
0312 friend constexpr bool operator==(ShortData lhs, ShortData rhs)
0313 { return lhs.status == rhs.status && lhs.msecs == rhs.msecs; }
0314 };
0315
0316 union Data {
0317
0318
0319
0320 static constexpr bool CanBeSmall = sizeof(ShortData) * 8 > 50;
0321
0322 Data() noexcept;
0323 Data(const QTimeZone &);
0324 Data(const Data &other) noexcept;
0325 Data(Data &&other) noexcept;
0326 Data &operator=(const Data &other) noexcept;
0327 Data &operator=(Data &&other) noexcept { swap(other); return *this; }
0328 ~Data();
0329
0330 void swap(Data &other) noexcept
0331 { std::swap(data, other.data); }
0332
0333 bool isShort() const;
0334 inline void invalidate();
0335 void detach();
0336 QTimeZone timeZone() const;
0337
0338 const QDateTimePrivate *operator->() const;
0339 QDateTimePrivate *operator->();
0340
0341 QDateTimePrivate *d;
0342 ShortData data;
0343 };
0344
0345 public:
0346 QDateTime() noexcept;
0347
0348 enum class TransitionResolution {
0349 Reject = 0,
0350 RelativeToBefore,
0351 RelativeToAfter,
0352 PreferBefore,
0353 PreferAfter,
0354 PreferStandard,
0355 PreferDaylightSaving,
0356
0357 LegacyBehavior = RelativeToBefore
0358 };
0359
0360 #if QT_DEPRECATED_SINCE(6, 9)
0361 QT_DEPRECATED_VERSION_X_6_9("Pass QTimeZone instead")
0362 QDateTime(QDate date, QTime time, Qt::TimeSpec spec, int offsetSeconds = 0);
0363 #endif
0364 #if QT_CORE_REMOVED_SINCE(6, 7)
0365 QDateTime(QDate date, QTime time, const QTimeZone &timeZone);
0366 QDateTime(QDate date, QTime time);
0367 #endif
0368 QDateTime(QDate date, QTime time, const QTimeZone &timeZone,
0369 TransitionResolution resolve = TransitionResolution::LegacyBehavior);
0370 QDateTime(QDate date, QTime time,
0371 TransitionResolution resolve = TransitionResolution::LegacyBehavior);
0372 QDateTime(const QDateTime &other) noexcept;
0373 QDateTime(QDateTime &&other) noexcept;
0374 ~QDateTime();
0375
0376 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QDateTime)
0377 QDateTime &operator=(const QDateTime &other) noexcept;
0378
0379 void swap(QDateTime &other) noexcept { d.swap(other.d); }
0380
0381 bool isNull() const;
0382 bool isValid() const;
0383
0384 QDate date() const;
0385 QTime time() const;
0386 Qt::TimeSpec timeSpec() const;
0387 int offsetFromUtc() const;
0388 QTimeZone timeRepresentation() const;
0389 #if QT_CONFIG(timezone)
0390 QTimeZone timeZone() const;
0391 #endif
0392 QString timeZoneAbbreviation() const;
0393 bool isDaylightTime() const;
0394
0395 qint64 toMSecsSinceEpoch() const;
0396 qint64 toSecsSinceEpoch() const;
0397
0398 #if QT_CORE_REMOVED_SINCE(6, 7)
0399 void setDate(QDate date);
0400 void setTime(QTime time);
0401 #endif
0402 void setDate(QDate date, TransitionResolution resolve = TransitionResolution::LegacyBehavior);
0403 void setTime(QTime time, TransitionResolution resolve = TransitionResolution::LegacyBehavior);
0404
0405 #if QT_DEPRECATED_SINCE(6, 9)
0406 QT_DEPRECATED_VERSION_X_6_9("Use setTimeZone() instead")
0407 void setTimeSpec(Qt::TimeSpec spec);
0408 QT_DEPRECATED_VERSION_X_6_9("Use setTimeZone() instead")
0409 void setOffsetFromUtc(int offsetSeconds);
0410 #endif
0411 #if QT_CORE_REMOVED_SINCE(6, 7)
0412 void setTimeZone(const QTimeZone &toZone);
0413 #endif
0414 void setTimeZone(const QTimeZone &toZone,
0415 TransitionResolution resolve = TransitionResolution::LegacyBehavior);
0416 void setMSecsSinceEpoch(qint64 msecs);
0417 void setSecsSinceEpoch(qint64 secs);
0418
0419 #if QT_CONFIG(datestring)
0420 QString toString(Qt::DateFormat format = Qt::TextDate) const;
0421 QString toString(const QString &format) const;
0422 QString toString(const QString &format, QCalendar cal) const
0423 { return toString(qToStringViewIgnoringNull(format), cal); }
0424 QString toString(QStringView format) const;
0425 QString toString(QStringView format, QCalendar cal) const;
0426 #endif
0427 [[nodiscard]] QDateTime addDays(qint64 days) const;
0428 [[nodiscard]] QDateTime addMonths(int months) const;
0429 [[nodiscard]] QDateTime addYears(int years) const;
0430 [[nodiscard]] QDateTime addSecs(qint64 secs) const;
0431 [[nodiscard]] QDateTime addMSecs(qint64 msecs) const;
0432 [[nodiscard]] QDateTime addDuration(std::chrono::milliseconds msecs) const
0433 {
0434 return addMSecs(msecs.count());
0435 }
0436
0437 #if QT_DEPRECATED_SINCE(6, 9)
0438 QT_DEPRECATED_VERSION_X_6_9("Use toTimeZone instead")
0439 QDateTime toTimeSpec(Qt::TimeSpec spec) const;
0440 #endif
0441 QDateTime toLocalTime() const;
0442 QDateTime toUTC() const;
0443 QDateTime toOffsetFromUtc(int offsetSeconds) const;
0444 QDateTime toTimeZone(const QTimeZone &toZone) const;
0445
0446 qint64 daysTo(const QDateTime &) const;
0447 qint64 secsTo(const QDateTime &) const;
0448 qint64 msecsTo(const QDateTime &) const;
0449
0450 static QDateTime currentDateTime(const QTimeZone &zone);
0451 static QDateTime currentDateTime();
0452 static QDateTime currentDateTimeUtc();
0453 #if QT_CONFIG(datestring)
0454
0455 static QDateTime fromString(QStringView string, Qt::DateFormat format = Qt::TextDate);
0456 static QDateTime fromString(const QString &string, Qt::DateFormat format = Qt::TextDate)
0457 { return fromString(qToStringViewIgnoringNull(string), format); }
0458
0459
0460 static QDateTime fromString(QStringView string, QStringView format, QCalendar cal)
0461 { return fromString(string.toString(), format, QLocale::DefaultTwoDigitBaseYear, cal); }
0462 QT_CORE_INLINE_SINCE(6, 7)
0463 static QDateTime fromString(const QString &string, QStringView format, QCalendar cal);
0464 static QDateTime fromString(const QString &string, const QString &format, QCalendar cal)
0465 { return fromString(string, qToStringViewIgnoringNull(format), QLocale::DefaultTwoDigitBaseYear, cal); }
0466
0467
0468
0469 static QDateTime fromString(QStringView string, QStringView format,
0470 int baseYear = QLocale::DefaultTwoDigitBaseYear)
0471 { return fromString(string.toString(), format, baseYear); }
0472 static QDateTime fromString(QStringView string, QStringView format,
0473 int baseYear, QCalendar cal)
0474 { return fromString(string.toString(), format, baseYear, cal); }
0475 static QDateTime fromString(const QString &string, QStringView format,
0476 int baseYear = QLocale::DefaultTwoDigitBaseYear);
0477 static QDateTime fromString(const QString &string, QStringView format,
0478 int baseYear, QCalendar cal);
0479 static QDateTime fromString(const QString &string, const QString &format,
0480 int baseYear = QLocale::DefaultTwoDigitBaseYear)
0481 { return fromString(string, qToStringViewIgnoringNull(format), baseYear); }
0482 static QDateTime fromString(const QString &string, const QString &format,
0483 int baseYear, QCalendar cal)
0484 { return fromString(string, qToStringViewIgnoringNull(format), baseYear, cal); }
0485 #endif
0486
0487 #if QT_DEPRECATED_SINCE(6, 9)
0488 QT_DEPRECATED_VERSION_X_6_9("Pass QTimeZone instead of time-spec, offset")
0489 static QDateTime fromMSecsSinceEpoch(qint64 msecs, Qt::TimeSpec spec, int offsetFromUtc = 0);
0490 QT_DEPRECATED_VERSION_X_6_9("Pass QTimeZone instead of time-spec, offset")
0491 static QDateTime fromSecsSinceEpoch(qint64 secs, Qt::TimeSpec spec, int offsetFromUtc = 0);
0492 #endif
0493
0494 static QDateTime fromMSecsSinceEpoch(qint64 msecs, const QTimeZone &timeZone);
0495 static QDateTime fromSecsSinceEpoch(qint64 secs, const QTimeZone &timeZone);
0496 static QDateTime fromMSecsSinceEpoch(qint64 msecs);
0497 static QDateTime fromSecsSinceEpoch(qint64 secs);
0498
0499 static qint64 currentMSecsSinceEpoch() noexcept;
0500 static qint64 currentSecsSinceEpoch() noexcept;
0501
0502 #if defined(Q_OS_DARWIN) || defined(Q_QDOC)
0503 static QDateTime fromCFDate(CFDateRef date);
0504 CFDateRef toCFDate() const Q_DECL_CF_RETURNS_RETAINED;
0505 static QDateTime fromNSDate(const NSDate *date);
0506 NSDate *toNSDate() const Q_DECL_NS_RETURNS_AUTORELEASED;
0507 #endif
0508
0509 static QDateTime fromStdTimePoint(
0510 std::chrono::time_point<
0511 std::chrono::system_clock,
0512 std::chrono::milliseconds
0513 > time
0514 );
0515
0516
0517 #if (__cpp_lib_chrono >= 201907L && !defined(Q_OS_INTEGRITY)) || defined(Q_QDOC)
0518 #if __cpp_concepts >= 201907L || defined(Q_QDOC)
0519 private:
0520
0521
0522 template <typename Clock, typename Duration>
0523 using system_clock_cast_duration = decltype(
0524 std::chrono::clock_cast<std::chrono::system_clock>(
0525 std::declval<const std::chrono::time_point<Clock, Duration> &>()
0526 ).time_since_epoch()
0527 );
0528
0529 public:
0530
0531 template <typename Clock, typename Duration>
0532 static QDateTime fromStdTimePoint(const std::chrono::time_point<Clock, Duration> &time)
0533 requires
0534 requires(const std::chrono::time_point<Clock, Duration> &t) {
0535
0536 std::chrono::clock_cast<std::chrono::system_clock>(t);
0537
0538
0539 requires std::is_convertible_v<
0540 system_clock_cast_duration<Clock, Duration>,
0541 std::chrono::milliseconds
0542 >;
0543 }
0544 {
0545 using namespace std::chrono;
0546 const sys_time<milliseconds> sysTime = clock_cast<system_clock>(time);
0547 return fromStdTimePoint(sysTime);
0548 }
0549 #endif
0550
0551
0552 QT_POST_CXX17_API_IN_EXPORTED_CLASS
0553 static QDateTime fromStdTimePoint(const std::chrono::local_time<std::chrono::milliseconds> &time)
0554 {
0555 return fromStdLocalTime(time);
0556 }
0557
0558 QT_POST_CXX17_API_IN_EXPORTED_CLASS
0559 static QDateTime fromStdLocalTime(const std::chrono::local_time<std::chrono::milliseconds> &time)
0560 {
0561 QDateTime result(QDate(1970, 1, 1), QTime(0, 0, 0), TransitionResolution::LegacyBehavior);
0562 return result.addMSecs(time.time_since_epoch().count());
0563 }
0564
0565 #if QT_CONFIG(timezone) && (__cpp_lib_chrono >= 201907L || defined(Q_QDOC))
0566
0567 QT_POST_CXX17_API_IN_EXPORTED_CLASS
0568 static QDateTime fromStdZonedTime(const std::chrono::zoned_time<
0569 std::chrono::milliseconds,
0570 const std::chrono::time_zone *
0571 > &time);
0572 #endif
0573
0574 QT_POST_CXX17_API_IN_EXPORTED_CLASS
0575 std::chrono::sys_time<std::chrono::milliseconds> toStdSysMilliseconds() const
0576 {
0577 const std::chrono::milliseconds duration(toMSecsSinceEpoch());
0578 return std::chrono::sys_time<std::chrono::milliseconds>(duration);
0579 }
0580
0581 QT_POST_CXX17_API_IN_EXPORTED_CLASS
0582 std::chrono::sys_seconds toStdSysSeconds() const
0583 {
0584 const std::chrono::seconds duration(toSecsSinceEpoch());
0585 return std::chrono::sys_seconds(duration);
0586 }
0587 #endif
0588
0589 friend std::chrono::milliseconds operator-(const QDateTime &lhs, const QDateTime &rhs)
0590 {
0591 return std::chrono::milliseconds(rhs.msecsTo(lhs));
0592 }
0593
0594 friend QDateTime operator+(const QDateTime &dateTime, std::chrono::milliseconds duration)
0595 {
0596 return dateTime.addMSecs(duration.count());
0597 }
0598
0599 friend QDateTime operator+(std::chrono::milliseconds duration, const QDateTime &dateTime)
0600 {
0601 return dateTime + duration;
0602 }
0603
0604 QDateTime &operator+=(std::chrono::milliseconds duration)
0605 {
0606 *this = addMSecs(duration.count());
0607 return *this;
0608 }
0609
0610 friend QDateTime operator-(const QDateTime &dateTime, std::chrono::milliseconds duration)
0611 {
0612 return dateTime.addMSecs(-duration.count());
0613 }
0614
0615 QDateTime &operator-=(std::chrono::milliseconds duration)
0616 {
0617 *this = addMSecs(-duration.count());
0618 return *this;
0619 }
0620
0621
0622
0623 enum class YearRange : qint32 { First = -292275056, Last = +292278994 };
0624
0625 private:
0626 bool equals(const QDateTime &other) const;
0627 #if QT_CORE_REMOVED_SINCE(6, 7)
0628 bool precedes(const QDateTime &other) const;
0629 #endif
0630 friend class QDateTimePrivate;
0631
0632 Data d;
0633
0634 friend bool comparesEqual(const QDateTime &lhs, const QDateTime &rhs)
0635 { return lhs.equals(rhs); }
0636 friend Q_CORE_EXPORT Qt::weak_ordering
0637 compareThreeWay(const QDateTime &lhs, const QDateTime &rhs);
0638 Q_DECLARE_WEAKLY_ORDERED_NON_NOEXCEPT(QDateTime)
0639
0640 #ifndef QT_NO_DATASTREAM
0641 friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QDateTime &);
0642 friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QDateTime &);
0643 #endif
0644
0645 #if !defined(QT_NO_DEBUG_STREAM) && QT_CONFIG(datestring)
0646 friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QDateTime &);
0647 #endif
0648 };
0649 Q_DECLARE_SHARED(QDateTime)
0650
0651 #ifndef QT_NO_DATASTREAM
0652 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, QDate);
0653 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QDate &);
0654 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, QTime);
0655 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QTime &);
0656 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QDateTime &);
0657 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QDateTime &);
0658 #endif
0659
0660 #if !defined(QT_NO_DEBUG_STREAM) && QT_CONFIG(datestring)
0661 Q_CORE_EXPORT QDebug operator<<(QDebug, QDate);
0662 Q_CORE_EXPORT QDebug operator<<(QDebug, QTime);
0663 Q_CORE_EXPORT QDebug operator<<(QDebug, const QDateTime &);
0664 #endif
0665
0666
0667
0668 Q_CORE_EXPORT size_t qHash(const QDateTime &key, size_t seed = 0);
0669 Q_CORE_EXPORT size_t qHash(QDate key, size_t seed = 0) noexcept;
0670 Q_CORE_EXPORT size_t qHash(QTime key, size_t seed = 0) noexcept;
0671
0672 #if QT_CONFIG(datestring) && QT_CORE_INLINE_IMPL_SINCE(6, 7)
0673 QDate QDate::fromString(const QString &string, QStringView format, QCalendar cal)
0674 {
0675 return fromString(string, format, QLocale::DefaultTwoDigitBaseYear, cal);
0676 }
0677
0678 QDateTime QDateTime::fromString(const QString &string, QStringView format, QCalendar cal)
0679 {
0680 return fromString(string, format, QLocale::DefaultTwoDigitBaseYear, cal);
0681 }
0682 #endif
0683
0684 QT_END_NAMESPACE
0685
0686 #endif