Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qdatetime.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// Copyright (C) 2021 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef QDATETIME_H
6#define QDATETIME_H
7
8#include <QtCore/qcalendar.h>
9#include <QtCore/qcompare.h>
10#include <QtCore/qlocale.h>
11#include <QtCore/qnamespace.h>
12#include <QtCore/qshareddata.h>
13#include <QtCore/qstring.h>
14
15#include <limits>
16#include <chrono>
17
18#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
21#endif
22
24
25class QTimeZone;
26class QDateTime;
27
28class Q_CORE_EXPORT QDate
29{
30 explicit constexpr QDate(qint64 julianDay) : jd(julianDay) {}
31public:
32 constexpr QDate() : jd(nullJd()) {}
33 QDate(int y, int m, int d);
34 QDate(int y, int m, int d, QCalendar cal);
35#if __cpp_lib_chrono >= 201907L || defined(Q_QDOC)
37 Q_IMPLICIT constexpr QDate(std::chrono::year_month_day date) noexcept
38 : jd(date.ok() ? stdSysDaysToJulianDay(date) : nullJd())
39 {}
40
42 Q_IMPLICIT constexpr QDate(std::chrono::year_month_day_last date) noexcept
43 : jd(date.ok() ? stdSysDaysToJulianDay(date) : nullJd())
44 {}
45
47 Q_IMPLICIT constexpr QDate(std::chrono::year_month_weekday date) noexcept
48 : jd(date.ok() ? stdSysDaysToJulianDay(date) : nullJd())
49 {}
50
52 Q_IMPLICIT constexpr QDate(std::chrono::year_month_weekday_last date) noexcept
53 : jd(date.ok() ? stdSysDaysToJulianDay(date) : nullJd())
54 {}
55
57 static constexpr QDate fromStdSysDays(const std::chrono::sys_days &days) noexcept
58 {
59 return QDate(stdSysDaysToJulianDay(days));
60 }
61
63 constexpr std::chrono::sys_days toStdSysDays() const noexcept
64 {
65 const qint64 days = isValid() ? jd - unixEpochJd() : 0;
66 return std::chrono::sys_days(std::chrono::days(days));
67 }
68#endif
69
70 constexpr bool isNull() const { return !isValid(); }
71 constexpr bool isValid() const { return jd >= minJd() && jd <= maxJd(); }
72
73 // Gregorian-optimized:
74 int year() const;
75 int month() const;
76 int day() const;
77 int dayOfWeek() const;
78 int dayOfYear() const;
79 int daysInMonth() const;
80 int daysInYear() const;
81 int weekNumber(int *yearNum = nullptr) const; // ISO 8601, always Gregorian
82
83 int year(QCalendar cal) const;
84 int month(QCalendar cal) const;
85 int day(QCalendar cal) const;
86 int dayOfWeek(QCalendar cal) const;
87 int dayOfYear(QCalendar cal) const;
88 int daysInMonth(QCalendar cal) const;
89 int daysInYear(QCalendar cal) const;
90
91#if QT_DEPRECATED_SINCE(6, 9)
92 QT_DEPRECATED_VERSION_X_6_9("Pass QTimeZone instead")
93 QDateTime startOfDay(Qt::TimeSpec spec, int offsetSeconds = 0) const;
95 QDateTime endOfDay(Qt::TimeSpec spec, int offsetSeconds = 0) const;
96#endif
97
98 QDateTime startOfDay(const QTimeZone &zone) const;
99 QDateTime endOfDay(const QTimeZone &zone) const;
100 QDateTime startOfDay() const;
101 QDateTime endOfDay() const;
102
103#if QT_CONFIG(datestring)
105 QString toString(const QString &format) const;
106 QString toString(const QString &format, QCalendar cal) const
107 { return toString(qToStringViewIgnoringNull(format), cal); }
110#endif
111 bool setDate(int year, int month, int day); // Gregorian-optimized
112 bool setDate(int year, int month, int day, QCalendar cal);
113
114 void getDate(int *year, int *month, int *day) const;
115
116 [[nodiscard]] QDate addDays(qint64 days) const;
117#if __cpp_lib_chrono >= 201907L || defined(Q_QDOC)
119 [[nodiscard]] QDate addDuration(std::chrono::days days) const
120 {
121 return addDays(days.count());
122 }
123#endif
124 // Gregorian-optimized:
125 [[nodiscard]] QDate addMonths(int months) const;
126 [[nodiscard]] QDate addYears(int years) const;
127 [[nodiscard]] QDate addMonths(int months, QCalendar cal) const;
128 [[nodiscard]] QDate addYears(int years, QCalendar cal) const;
129 qint64 daysTo(QDate d) const;
130
132#if QT_CONFIG(datestring)
133 // No DateFormat accepts a two-digit year, so no need for baseYear:
136 { return fromString(qToStringViewIgnoringNull(string), format); }
137
138 // Accept calendar without over-ride of base year:
141 QT_CORE_INLINE_SINCE(6, 7)
142 static QDate fromString(const QString &string, QStringView format, QCalendar cal);
143 static QDate fromString(const QString &string, const QString &format, QCalendar cal)
145
146 // Overriding base year is likely more common than overriding calendar (and
147 // likely to get more so, as the legacy base drops ever further behind us).
150 { return fromString(string.toString(), format, baseYear); }
152 int baseYear, QCalendar cal)
153 { return fromString(string.toString(), format, baseYear, cal); }
154 static QDate fromString(const QString &string, QStringView format,
155 int baseYear = QLocale::DefaultTwoDigitBaseYear);
156 static QDate fromString(const QString &string, QStringView format,
157 int baseYear, QCalendar cal);
158 static QDate fromString(const QString &string, const QString &format,
160 { return fromString(string, qToStringViewIgnoringNull(format), baseYear); }
161 static QDate fromString(const QString &string, const QString &format,
162 int baseYear, QCalendar cal)
163 { return fromString(string, qToStringViewIgnoringNull(format), baseYear, cal); }
164#endif
165 static bool isValid(int y, int m, int d);
166 static bool isLeapYear(int year);
167
168 static constexpr inline QDate fromJulianDay(qint64 jd_)
169 { return jd_ >= minJd() && jd_ <= maxJd() ? QDate(jd_) : QDate() ; }
170 constexpr inline qint64 toJulianDay() const { return jd; }
171
172private:
173 // using extra parentheses around min to avoid expanding it if it is a macro
174 static constexpr inline qint64 nullJd() { return (std::numeric_limits<qint64>::min)(); }
175 static constexpr inline qint64 minJd() { return Q_INT64_C(-784350574879); }
176 static constexpr inline qint64 maxJd() { return Q_INT64_C( 784354017364); }
177 static constexpr inline qint64 unixEpochJd() { return Q_INT64_C(2440588); }
178
179#if __cpp_lib_chrono >= 201907L
180 static constexpr qint64 stdSysDaysToJulianDay(const std::chrono::sys_days &days) noexcept
181 {
182 const auto epochDays = days.time_since_epoch().count();
183 // minJd() and maxJd() fit into 40 bits.
184 if constexpr (sizeof(epochDays) * CHAR_BIT >= 41) {
185 constexpr auto top = maxJd() - unixEpochJd();
186 constexpr auto bottom = minJd() - unixEpochJd();
187 if (epochDays > top || epochDays < bottom)
188 return nullJd();
189 }
190 return unixEpochJd() + epochDays;
191 }
192#endif // __cpp_lib_chrono >= 201907L
193
194 qint64 jd;
195
196 friend class QDateTime;
197 friend class QDateTimeParser;
198 friend class QDateTimePrivate;
199
200 friend constexpr bool comparesEqual(const QDate &lhs, const QDate &rhs) noexcept
201 { return lhs.jd == rhs.jd; }
202 friend constexpr Qt::strong_ordering
203 compareThreeWay(const QDate &lhs, const QDate &rhs) noexcept
204 { return Qt::compareThreeWay(lhs.jd, rhs.jd); }
206
207#ifndef QT_NO_DATASTREAM
208 friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, QDate);
209 friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QDate &);
210#endif
211};
213
214class Q_CORE_EXPORT QTime
215{
216 explicit constexpr QTime(int ms) : mds(ms)
217 {}
218public:
219 constexpr QTime(): mds(NullTime)
220 {}
221 QTime(int h, int m, int s = 0, int ms = 0);
222
223 constexpr bool isNull() const { return mds == NullTime; }
224 bool isValid() const;
225
226 int hour() const;
227 int minute() const;
228 int second() const;
229 int msec() const;
230#if QT_CONFIG(datestring)
232 QString toString(const QString &format) const
235#endif
236 bool setHMS(int h, int m, int s, int ms = 0);
237
238 [[nodiscard]] QTime addSecs(int secs) const;
239 int secsTo(QTime t) const;
240 [[nodiscard]] QTime addMSecs(int ms) const;
241 int msecsTo(QTime t) const;
242
243 static constexpr inline QTime fromMSecsSinceStartOfDay(int msecs) { return QTime(msecs); }
244 constexpr inline int msecsSinceStartOfDay() const { return mds == NullTime ? 0 : mds; }
245
247#if QT_CONFIG(datestring)
250 { return fromString(string.toString(), format); }
251 static QTime fromString(const QString &string, QStringView format);
253 { return fromString(qToStringViewIgnoringNull(string), format); }
254 static QTime fromString(const QString &string, const QString &format)
255 { return fromString(string, qToStringViewIgnoringNull(format)); }
256#endif
257 static bool isValid(int h, int m, int s, int ms = 0);
258
259private:
260 enum TimeFlag { NullTime = -1 };
261 constexpr inline int ds() const { return mds == -1 ? 0 : mds; }
262 int mds;
263
264 friend constexpr bool comparesEqual(const QTime &lhs, const QTime &rhs) noexcept
265 { return lhs.mds == rhs.mds; }
266 friend constexpr Qt::strong_ordering
267 compareThreeWay(const QTime &lhs, const QTime &rhs) noexcept
268 { return Qt::compareThreeWay(lhs.mds, rhs.mds); }
270
271 friend class QDateTime;
272 friend class QDateTimePrivate;
273#ifndef QT_NO_DATASTREAM
274 friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, QTime);
275 friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QTime &);
276#endif
277};
279
280class QDateTimePrivate;
281
282class Q_CORE_EXPORT QDateTime
283{
284 struct ShortData {
285#if QT_VERSION >= QT_VERSION_CHECK(7,0,0) || defined(QT_BOOTSTRAPPED)
286# if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
287 qint64 status : 8;
288# endif
289 qint64 msecs : 56;
290
291# if Q_BYTE_ORDER == Q_BIG_ENDIAN
292 qint64 status : 8;
293# endif
294#else
295# if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
296 quintptr status : 8;
297# endif
298 // note: this is only 24 bits on 32-bit systems...
299 qintptr msecs : sizeof(void *) * 8 - 8;
300
301# if Q_BYTE_ORDER == Q_BIG_ENDIAN
302 quintptr status : 8;
303# endif
304#endif
305 friend constexpr bool operator==(ShortData lhs, ShortData rhs)
306 { return lhs.status == rhs.status && lhs.msecs == rhs.msecs; }
307 };
308
309 union Data {
310 // To be of any use, we need at least 60 years around 1970, which
311 // is 1,893,456,000,000 ms. That requires 41 bits to store, plus
312 // the sign bit. With the status byte, the minimum size is 50 bits.
313 static constexpr bool CanBeSmall = sizeof(ShortData) * 8 > 50;
314
315 Data() noexcept;
316 Data(const QTimeZone &);
317 Data(const Data &other) noexcept;
318 Data(Data &&other) noexcept;
319 Data &operator=(const Data &other) noexcept;
320 Data &operator=(Data &&other) noexcept { swap(other); return *this; }
321 ~Data();
322
323 void swap(Data &other) noexcept
324 { std::swap(data, other.data); }
325
326 bool isShort() const;
327 inline void invalidate();
328 void detach();
329 QTimeZone timeZone() const;
330
331 const QDateTimePrivate *operator->() const;
332 QDateTimePrivate *operator->();
333
335 ShortData data;
336 };
337
338public:
339 QDateTime() noexcept;
340
342 Reject = 0,
343 RelativeToBefore,
344 RelativeToAfter,
345 PreferBefore,
346 PreferAfter,
347 PreferStandard,
348 PreferDaylightSaving,
349 // Closest match to behavior prior to introducing TransitionResolution:
350 LegacyBehavior = RelativeToBefore
351 };
352
353#if QT_DEPRECATED_SINCE(6, 9)
354 QT_DEPRECATED_VERSION_X_6_9("Pass QTimeZone instead")
355 QDateTime(QDate date, QTime time, Qt::TimeSpec spec, int offsetSeconds = 0);
356#endif
357#if QT_CORE_REMOVED_SINCE(6, 7)
358 QDateTime(QDate date, QTime time, const QTimeZone &timeZone);
360#endif
361 QDateTime(QDate date, QTime time, const QTimeZone &timeZone,
362 TransitionResolution resolve = TransitionResolution::LegacyBehavior);
364 TransitionResolution resolve = TransitionResolution::LegacyBehavior);
365 QDateTime(const QDateTime &other) noexcept;
366 QDateTime(QDateTime &&other) noexcept;
367 ~QDateTime();
368
369 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QDateTime)
370 QDateTime &operator=(const QDateTime &other) noexcept;
371
372 void swap(QDateTime &other) noexcept { d.swap(other.d); }
373
374 bool isNull() const;
375 bool isValid() const;
376
377 QDate date() const;
378 QTime time() const;
379 Qt::TimeSpec timeSpec() const;
380 int offsetFromUtc() const;
381 QTimeZone timeRepresentation() const;
382#if QT_CONFIG(timezone)
383 QTimeZone timeZone() const;
384#endif // timezone
385 QString timeZoneAbbreviation() const;
386 bool isDaylightTime() const;
387
388 qint64 toMSecsSinceEpoch() const;
389 qint64 toSecsSinceEpoch() const;
390
391#if QT_CORE_REMOVED_SINCE(6, 7)
392 void setDate(QDate date);
393 void setTime(QTime time);
394#endif
395 void setDate(QDate date, TransitionResolution resolve = TransitionResolution::LegacyBehavior);
396 void setTime(QTime time, TransitionResolution resolve = TransitionResolution::LegacyBehavior);
397
398#if QT_DEPRECATED_SINCE(6, 9)
399 QT_DEPRECATED_VERSION_X_6_9("Use setTimeZone() instead")
400 void setTimeSpec(Qt::TimeSpec spec);
401 QT_DEPRECATED_VERSION_X_6_9("Use setTimeZone() instead")
402 void setOffsetFromUtc(int offsetSeconds);
403#endif
404#if QT_CORE_REMOVED_SINCE(6, 7)
405 void setTimeZone(const QTimeZone &toZone);
406#endif
407 void setTimeZone(const QTimeZone &toZone,
408 TransitionResolution resolve = TransitionResolution::LegacyBehavior);
409 void setMSecsSinceEpoch(qint64 msecs);
410 void setSecsSinceEpoch(qint64 secs);
411
412#if QT_CONFIG(datestring)
414 QString toString(const QString &format) const;
415 QString toString(const QString &format, QCalendar cal) const
416 { return toString(qToStringViewIgnoringNull(format), cal); }
419#endif
420 [[nodiscard]] QDateTime addDays(qint64 days) const;
421 [[nodiscard]] QDateTime addMonths(int months) const;
422 [[nodiscard]] QDateTime addYears(int years) const;
423 [[nodiscard]] QDateTime addSecs(qint64 secs) const;
424 [[nodiscard]] QDateTime addMSecs(qint64 msecs) const;
425 [[nodiscard]] QDateTime addDuration(std::chrono::milliseconds msecs) const
426 {
427 return addMSecs(msecs.count());
428 }
429
430#if QT_DEPRECATED_SINCE(6, 9)
431 QT_DEPRECATED_VERSION_X_6_9("Use toTimeZone instead")
432 QDateTime toTimeSpec(Qt::TimeSpec spec) const;
433#endif
434 QDateTime toLocalTime() const;
435 QDateTime toUTC() const;
436 QDateTime toOffsetFromUtc(int offsetSeconds) const;
437 QDateTime toTimeZone(const QTimeZone &toZone) const;
438
439 qint64 daysTo(const QDateTime &) const;
440 qint64 secsTo(const QDateTime &) const;
441 qint64 msecsTo(const QDateTime &) const;
442
444 static QDateTime currentDateTime();
445 static QDateTime currentDateTimeUtc();
446#if QT_CONFIG(datestring)
447 // No DateFormat accepts a two-digit year, so no need for baseYear:
450 { return fromString(qToStringViewIgnoringNull(string), format); }
451
452 // Accept calendar without over-ride of base year:
455 QT_CORE_INLINE_SINCE(6, 7)
456 static QDateTime fromString(const QString &string, QStringView format, QCalendar cal);
457 static QDateTime fromString(const QString &string, const QString &format, QCalendar cal)
459
460 // Overriding base year is likely more common than overriding calendar (and
461 // likely to get more so, as the legacy base drops ever further behind us).
464 { return fromString(string.toString(), format, baseYear); }
466 int baseYear, QCalendar cal)
467 { return fromString(string.toString(), format, baseYear, cal); }
468 static QDateTime fromString(const QString &string, QStringView format,
469 int baseYear = QLocale::DefaultTwoDigitBaseYear);
470 static QDateTime fromString(const QString &string, QStringView format,
471 int baseYear, QCalendar cal);
472 static QDateTime fromString(const QString &string, const QString &format,
474 { return fromString(string, qToStringViewIgnoringNull(format), baseYear); }
475 static QDateTime fromString(const QString &string, const QString &format,
476 int baseYear, QCalendar cal)
477 { return fromString(string, qToStringViewIgnoringNull(format), baseYear, cal); }
478#endif
479
480#if QT_DEPRECATED_SINCE(6, 9)
481 QT_DEPRECATED_VERSION_X_6_9("Pass QTimeZone instead of time-spec, offset")
482 static QDateTime fromMSecsSinceEpoch(qint64 msecs, Qt::TimeSpec spec, int offsetFromUtc = 0);
483 QT_DEPRECATED_VERSION_X_6_9("Pass QTimeZone instead of time-spec, offset")
484 static QDateTime fromSecsSinceEpoch(qint64 secs, Qt::TimeSpec spec, int offsetFromUtc = 0);
485#endif
486
487 static QDateTime fromMSecsSinceEpoch(qint64 msecs, const QTimeZone &timeZone);
488 static QDateTime fromSecsSinceEpoch(qint64 secs, const QTimeZone &timeZone);
489 static QDateTime fromMSecsSinceEpoch(qint64 msecs);
490 static QDateTime fromSecsSinceEpoch(qint64 secs);
491
493 static qint64 currentSecsSinceEpoch() noexcept;
494
495#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
496 static QDateTime fromCFDate(CFDateRef date);
497 CFDateRef toCFDate() const Q_DECL_CF_RETURNS_RETAINED;
498 static QDateTime fromNSDate(const NSDate *date);
499 NSDate *toNSDate() const Q_DECL_NS_RETURNS_AUTORELEASED;
500#endif
501
502#if __cpp_lib_chrono >= 201907L || defined(Q_QDOC)
503#if __cpp_concepts >= 201907L || defined(Q_QDOC)
504 // Generic clock, as long as it's compatible with us (= system_clock)
505 template <typename Clock, typename Duration>
506 static QDateTime fromStdTimePoint(const std::chrono::time_point<Clock, Duration> &time)
507 requires
508 requires(const std::chrono::time_point<Clock, Duration> &t) {
509 // the clock can be converted to system_clock
510 std::chrono::clock_cast<std::chrono::system_clock>(t);
511 // the duration can be converted to milliseconds
512 requires std::is_convertible_v<Duration, std::chrono::milliseconds>;
513 }
514 {
515 const auto sysTime = std::chrono::clock_cast<std::chrono::system_clock>(time);
516 // clock_cast can change the duration, so convert it again to milliseconds
517 const auto timeInMSec = std::chrono::time_point_cast<std::chrono::milliseconds>(sysTime);
518 return fromMSecsSinceEpoch(timeInMSec.time_since_epoch().count(), Qt::UTC);
519 }
520#endif // __cpp_concepts
521
522 // local_time
524 static QDateTime fromStdTimePoint(const std::chrono::local_time<std::chrono::milliseconds> &time)
525 {
526 return fromStdLocalTime(time);
527 }
528
530 static QDateTime fromStdLocalTime(const std::chrono::local_time<std::chrono::milliseconds> &time)
531 {
532 QDateTime result(QDate(1970, 1, 1), QTime(0, 0, 0), TransitionResolution::LegacyBehavior);
533 return result.addMSecs(time.time_since_epoch().count());
534 }
535
536#if QT_CONFIG(timezone) && (__cpp_lib_chrono >= 201907L || defined(Q_QDOC))
537 // zoned_time. defined in qtimezone.h
539 static QDateTime fromStdZonedTime(const std::chrono::zoned_time<
540 std::chrono::milliseconds,
541 const std::chrono::time_zone *
542 > &time);
543#endif // QT_CONFIG(timezone)
544
546 std::chrono::sys_time<std::chrono::milliseconds> toStdSysMilliseconds() const
547 {
548 const std::chrono::milliseconds duration(toMSecsSinceEpoch());
549 return std::chrono::sys_time<std::chrono::milliseconds>(duration);
550 }
551
553 std::chrono::sys_seconds toStdSysSeconds() const
554 {
555 const std::chrono::seconds duration(toSecsSinceEpoch());
556 return std::chrono::sys_seconds(duration);
557 }
558#endif // __cpp_lib_chrono >= 201907L
559
560 friend std::chrono::milliseconds operator-(const QDateTime &lhs, const QDateTime &rhs)
561 {
562 return std::chrono::milliseconds(rhs.msecsTo(lhs));
563 }
564
565 friend QDateTime operator+(const QDateTime &dateTime, std::chrono::milliseconds duration)
566 {
567 return dateTime.addMSecs(duration.count());
568 }
569
570 friend QDateTime operator+(std::chrono::milliseconds duration, const QDateTime &dateTime)
571 {
572 return dateTime + duration;
573 }
574
575 QDateTime &operator+=(std::chrono::milliseconds duration)
576 {
577 *this = addMSecs(duration.count());
578 return *this;
579 }
580
581 friend QDateTime operator-(const QDateTime &dateTime, std::chrono::milliseconds duration)
582 {
583 return dateTime.addMSecs(-duration.count());
584 }
585
586 QDateTime &operator-=(std::chrono::milliseconds duration)
587 {
588 *this = addMSecs(-duration.count());
589 return *this;
590 }
591
592 // (1<<63) ms is 292277024.6 (average Gregorian) years, counted from the start of 1970, so
593 // Last is floor(1970 + 292277024.6); no year 0, so First is floor(1970 - 1 - 292277024.6)
594 enum class YearRange : qint32 { First = -292275056, Last = +292278994 };
595
596private:
597 bool equals(const QDateTime &other) const;
598#if QT_CORE_REMOVED_SINCE(6, 7)
599 bool precedes(const QDateTime &other) const;
600#endif
601 friend class QDateTimePrivate;
602
603 Data d;
604
605 friend bool comparesEqual(const QDateTime &lhs, const QDateTime &rhs)
606 { return lhs.equals(rhs); }
607 friend Q_CORE_EXPORT Qt::weak_ordering
608 compareThreeWay(const QDateTime &lhs, const QDateTime &rhs);
610
611#ifndef QT_NO_DATASTREAM
612 friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QDateTime &);
613 friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QDateTime &);
614#endif
615
616#if !defined(QT_NO_DEBUG_STREAM) && QT_CONFIG(datestring)
617 friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QDateTime &);
618#endif
619};
620Q_DECLARE_SHARED(QDateTime)
621
622#ifndef QT_NO_DATASTREAM
627Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QDateTime &);
629#endif // QT_NO_DATASTREAM
630
631#if !defined(QT_NO_DEBUG_STREAM) && QT_CONFIG(datestring)
632Q_CORE_EXPORT QDebug operator<<(QDebug, QDate);
633Q_CORE_EXPORT QDebug operator<<(QDebug, QTime);
634Q_CORE_EXPORT QDebug operator<<(QDebug, const QDateTime &);
635#endif
636
637// QDateTime is not noexcept for now -- to be revised once
638// timezone and calendaring support is added
639Q_CORE_EXPORT size_t qHash(const QDateTime &key, size_t seed = 0);
640Q_CORE_EXPORT size_t qHash(QDate key, size_t seed = 0) noexcept;
641Q_CORE_EXPORT size_t qHash(QTime key, size_t seed = 0) noexcept;
642
643#if QT_CONFIG(datestring) && QT_CORE_INLINE_IMPL_SINCE(6, 7)
644QDate QDate::fromString(const QString &string, QStringView format, QCalendar cal)
645{
647}
648
649QDateTime QDateTime::fromString(const QString &string, QStringView format, QCalendar cal)
650{
652}
653#endif
654
656
657#endif // QDATETIME_H
The QCalendar class describes calendar systems.
Definition qcalendar.h:53
\inmodule QtCore\reentrant
Definition qdatastream.h:46
\inmodule QtCore\reentrant
Definition qdatetime.h:283
QDateTime & operator+=(std::chrono::milliseconds duration)
Definition qdatetime.h:575
QDateTime addMSecs(qint64 msecs) const
Returns a QDateTime object containing a datetime msecs milliseconds later than the datetime of this o...
qint64 msecsTo(const QDateTime &) const
Returns the number of milliseconds from this datetime to the other datetime.
TransitionResolution
Definition qdatetime.h:341
friend QDateTime operator+(const QDateTime &dateTime, std::chrono::milliseconds duration)
Definition qdatetime.h:565
friend bool comparesEqual(const QDateTime &lhs, const QDateTime &rhs)
Definition qdatetime.h:605
QDateTime addDuration(std::chrono::milliseconds msecs) const
Definition qdatetime.h:425
QDateTime & operator-=(std::chrono::milliseconds duration)
Definition qdatetime.h:586
friend QDateTime operator+(std::chrono::milliseconds duration, const QDateTime &dateTime)
Definition qdatetime.h:570
static qint64 currentMSecsSinceEpoch() noexcept
static QDateTime currentDateTime(const QTimeZone &zone)
friend QDateTime operator-(const QDateTime &dateTime, std::chrono::milliseconds duration)
Definition qdatetime.h:581
friend std::chrono::milliseconds operator-(const QDateTime &lhs, const QDateTime &rhs)
Definition qdatetime.h:560
void swap(QDateTime &other) noexcept
Definition qdatetime.h:372
\inmodule QtCore \reentrant
Definition qdatetime.h:29
constexpr bool isValid() const
Returns true if this date is valid; otherwise returns false.
Definition qdatetime.h:71
constexpr qint64 toJulianDay() const
Converts the date to a Julian day.
Definition qdatetime.h:170
static constexpr QDate fromJulianDay(qint64 jd_)
Converts the Julian day jd to a QDate.
Definition qdatetime.h:168
friend constexpr Qt::strong_ordering compareThreeWay(const QDate &lhs, const QDate &rhs) noexcept
Definition qdatetime.h:203
constexpr bool isNull() const
Returns true if the date is null; otherwise returns false.
Definition qdatetime.h:70
static QDate currentDate()
Returns the system clock's current date.
constexpr QDate()
Constructs a null date.
Definition qdatetime.h:32
friend constexpr bool comparesEqual(const QDate &lhs, const QDate &rhs) noexcept
Definition qdatetime.h:200
\inmodule QtCore
static constexpr int DefaultTwoDigitBaseYear
Definition qlocale.h:39
\inmodule QtCore
Definition qstringview.h:78
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qtimezone.h:26
\inmodule QtCore \reentrant
Definition qdatetime.h:215
constexpr bool isNull() const
Returns true if the time is null (i.e., the QTime object was constructed using the default constructo...
Definition qdatetime.h:223
static QTime currentTime()
Returns the current time as reported by the system clock.
friend constexpr Qt::strong_ordering compareThreeWay(const QTime &lhs, const QTime &rhs) noexcept
Definition qdatetime.h:267
static constexpr QTime fromMSecsSinceStartOfDay(int msecs)
Returns a new QTime instance with the time set to the number of msecs since the start of the day,...
Definition qdatetime.h:243
friend constexpr bool comparesEqual(const QTime &lhs, const QTime &rhs) noexcept
Definition qdatetime.h:264
constexpr int msecsSinceStartOfDay() const
Returns the number of msecs since the start of the day, i.e.
Definition qdatetime.h:244
constexpr QTime()
Constructs a null time object.
Definition qdatetime.h:219
\inmodule QtCore \title Classes and helpers for defining comparison operators \keyword qtcompare
Definition qcompare.h:400
\variable Qt::strong_ordering::less
Definition qcompare.h:221
QDate date
[1]
Combined button and popup list for selecting options.
Definition qcompare.h:63
@ UTC
constexpr Qt::strong_ordering compareThreeWay(LeftInt lhs, RightInt rhs) noexcept
DateFormat
@ TextDate
std::chrono::duration< IntRep, std::ratio< 86400 > > days
Definition q20chrono.h:52
#define Q_DECLARE_WEAKLY_ORDERED(...)
#define Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(...)
#define QT_POST_CXX17_API_IN_EXPORTED_CLASS
#define Q_DECL_NS_RETURNS_AUTORELEASED
#define Q_DECL_CF_RETURNS_RETAINED
#define Q_IMPLICIT
#define Q_FORWARD_DECLARE_CF_TYPE(type)
#define Q_FORWARD_DECLARE_OBJC_CLASS(classname)
QDateTimePrivate::QDateTimeShortData ShortData
Q_CORE_EXPORT QDataStream & operator>>(QDataStream &, QDate &)
Q_CORE_EXPORT size_t qHash(const QDateTime &key, size_t seed=0)
Q_CORE_EXPORT QDataStream & operator<<(QDataStream &, QDate)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
static const char months[]
static qint64 msecsTo(const QDateTime &from, const QDateTime &to)
const GLfloat * m
GLuint64 key
GLdouble GLdouble GLdouble GLdouble top
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat GLfloat f
GLint GLint bottom
GLenum GLuint GLintptr offset
GLint GLsizei GLsizei GLenum format
GLint y
GLfloat GLfloat GLfloat GLfloat h
GLdouble s
[6]
Definition qopenglext.h:235
GLdouble GLdouble t
Definition qopenglext.h:243
GLuint64EXT * result
[6]
static bool fromString(const QMetaObject *mo, QString s, Allocate &&allocate)
static const QQmlJSScope * resolve(const QQmlJSScope *current, const QStringList &names)
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
Definition qrandom.cpp:1220
QStringView qToStringViewIgnoringNull(const QStringLike &s) noexcept
#define QT_DEPRECATED_VERSION_X_6_9(text)
@ Q_RELOCATABLE_TYPE
Definition qtypeinfo.h:158
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:180
size_t quintptr
Definition qtypes.h:167
int qint32
Definition qtypes.h:49
long long qint64
Definition qtypes.h:60
#define Q_INT64_C(c)
Definition qtypes.h:57
ptrdiff_t qintptr
Definition qtypes.h:166
Qt::weak_ordering compareThreeWay(const QUrl &lhs, const QUrl &rhs)
Definition qurl.cpp:3079
QDataStream & operator<<(QDataStream &out, const MyClass &myObj)
[4]
QDataStream & operator>>(QDataStream &in, MyClass &myObj)
QDateTime dateTime
[12]
d1 daysTo(d2)
QSharedPointer< T > other(t)
[5]
this swap(other)
char * toString(const MyType &t)
[31]