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>
18#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
30 explicit constexpr QDate(
qint64 julianDay) : jd(julianDay) {}
32 constexpr QDate() : jd(nullJd()) {}
35#if __cpp_lib_chrono >= 201907L || defined(Q_QDOC)
38 : jd(
date.ok() ? stdSysDaysToJulianDay(
date) : nullJd())
43 : jd(
date.ok() ? stdSysDaysToJulianDay(
date) : nullJd())
48 : jd(
date.ok() ? stdSysDaysToJulianDay(
date) : nullJd())
53 : jd(
date.ok() ? stdSysDaysToJulianDay(
date) : nullJd())
57 static constexpr QDate fromStdSysDays(
const std::chrono::sys_days &days)
noexcept
59 return QDate(stdSysDaysToJulianDay(days));
63 constexpr std::chrono::sys_days toStdSysDays() const noexcept
65 const qint64 days = isValid() ? jd - unixEpochJd() : 0;
66 return std::chrono::sys_days(std::chrono::days(days));
70 constexpr bool isNull()
const {
return !isValid(); }
71 constexpr bool isValid()
const {
return jd >= minJd() && jd <= maxJd(); }
77 int dayOfWeek()
const;
78 int dayOfYear()
const;
79 int daysInMonth()
const;
80 int daysInYear()
const;
81 int weekNumber(
int *yearNum =
nullptr)
const;
91#if QT_DEPRECATED_SINCE(6, 9)
93 QDateTime startOfDay(
Qt::TimeSpec spec,
int offsetSeconds = 0) const;
95 QDateTime endOfDay(
Qt::TimeSpec spec,
int offsetSeconds = 0) const;
103#if QT_CONFIG(datestring)
111 bool setDate(
int year,
int month,
int day);
112 bool setDate(
int year,
int month,
int day,
QCalendar cal);
114 void getDate(
int *year,
int *month,
int *day)
const;
117#if __cpp_lib_chrono >= 201907L || defined(Q_QDOC)
119 [[nodiscard]]
QDate addDuration(std::chrono::days days)
const
121 return addDays(
days.count());
126 [[nodiscard]]
QDate addYears(
int years)
const;
132#if QT_CONFIG(datestring)
141 QT_CORE_INLINE_SINCE(6, 7)
165 static bool isValid(
int y,
int m,
int d);
166 static bool isLeapYear(
int year);
169 {
return jd_ >= minJd() && jd_ <= maxJd() ?
QDate(jd_) :
QDate() ; }
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); }
179#if __cpp_lib_chrono >= 201907L
180 static constexpr qint64 stdSysDaysToJulianDay(
const std::chrono::sys_days &days)
noexcept
182 const auto epochDays =
days.time_since_epoch().count();
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)
190 return unixEpochJd() + epochDays;
201 {
return lhs.jd == rhs.jd; }
207#ifndef QT_NO_DATASTREAM
216 explicit constexpr QTime(
int ms) : mds(ms)
221 QTime(
int h,
int m,
int s = 0,
int ms = 0);
223 constexpr bool isNull()
const {
return mds == NullTime; }
224 bool isValid()
const;
230#if QT_CONFIG(datestring)
236 bool setHMS(
int h,
int m,
int s,
int ms = 0);
238 [[nodiscard]]
QTime addSecs(
int secs)
const;
239 int secsTo(
QTime t)
const;
240 [[nodiscard]]
QTime addMSecs(
int ms)
const;
247#if QT_CONFIG(datestring)
257 static bool isValid(
int h,
int m,
int s,
int ms = 0);
260 enum TimeFlag { NullTime = -1 };
261 constexpr inline int ds()
const {
return mds == -1 ? 0 : mds; }
265 {
return lhs.mds == rhs.mds; }
273#ifndef QT_NO_DATASTREAM
285#if QT_VERSION >= QT_VERSION_CHECK(7,0,0) || defined(QT_BOOTSTRAPPED)
286# if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
291# if Q_BYTE_ORDER == Q_BIG_ENDIAN
295# if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
299 qintptr msecs :
sizeof(
void *) * 8 - 8;
301# if Q_BYTE_ORDER == Q_BIG_ENDIAN
305 friend constexpr bool operator==(ShortData lhs, ShortData rhs)
306 {
return lhs.status == rhs.status && lhs.msecs == rhs.msecs; }
313 static constexpr bool CanBeSmall =
sizeof(
ShortData) * 8 > 50;
319 Data &operator=(
const Data &
other)
noexcept;
320 Data &operator=(Data &&
other)
noexcept {
swap(
other);
return *
this; }
326 bool isShort()
const;
327 inline void invalidate();
348 PreferDaylightSaving,
350 LegacyBehavior = RelativeToBefore
353#if QT_DEPRECATED_SINCE(6, 9)
357#if QT_CORE_REMOVED_SINCE(6, 7)
362 TransitionResolution
resolve = TransitionResolution::LegacyBehavior);
364 TransitionResolution
resolve = TransitionResolution::LegacyBehavior);
369 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(
QDateTime)
375 bool isValid()
const;
380 int offsetFromUtc()
const;
382#if QT_CONFIG(timezone)
385 QString timeZoneAbbreviation()
const;
386 bool isDaylightTime()
const;
388 qint64 toMSecsSinceEpoch()
const;
389 qint64 toSecsSinceEpoch()
const;
391#if QT_CORE_REMOVED_SINCE(6, 7)
395 void setDate(
QDate date, TransitionResolution
resolve = TransitionResolution::LegacyBehavior);
396 void setTime(
QTime time, TransitionResolution
resolve = TransitionResolution::LegacyBehavior);
398#if QT_DEPRECATED_SINCE(6, 9)
400 void setTimeSpec(
Qt::TimeSpec spec);
402 void setOffsetFromUtc(
int offsetSeconds);
404#if QT_CORE_REMOVED_SINCE(6, 7)
405 void setTimeZone(
const QTimeZone &toZone);
407 void setTimeZone(
const QTimeZone &toZone,
408 TransitionResolution
resolve = TransitionResolution::LegacyBehavior);
409 void setMSecsSinceEpoch(
qint64 msecs);
410 void setSecsSinceEpoch(
qint64 secs);
412#if QT_CONFIG(datestring)
422 [[nodiscard]]
QDateTime addYears(
int years)
const;
427 return addMSecs(msecs.count());
430#if QT_DEPRECATED_SINCE(6, 9)
436 QDateTime toOffsetFromUtc(
int offsetSeconds)
const;
446#if QT_CONFIG(datestring)
455 QT_CORE_INLINE_SINCE(6, 7)
480#if QT_DEPRECATED_SINCE(6, 9)
482 static
QDateTime fromMSecsSinceEpoch(
qint64 msecs,
Qt::TimeSpec spec,
int offsetFromUtc = 0);
484 static
QDateTime fromSecsSinceEpoch(
qint64 secs,
Qt::TimeSpec spec,
int offsetFromUtc = 0);
493 static
qint64 currentSecsSinceEpoch() noexcept;
495#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
502#if __cpp_lib_chrono >= 201907L || defined(Q_QDOC)
503#if __cpp_concepts >= 201907L || defined(Q_QDOC)
505 template <
typename Clock,
typename Duration>
506 static QDateTime fromStdTimePoint(
const std::chrono::time_point<Clock, Duration> &
time)
508 requires(
const std::chrono::time_point<Clock, Duration> &
t) {
510 std::chrono::clock_cast<std::chrono::system_clock>(
t);
512 requires std::is_convertible_v<Duration, std::chrono::milliseconds>;
515 const auto sysTime = std::chrono::clock_cast<std::chrono::system_clock>(
time);
517 const auto timeInMSec = std::chrono::time_point_cast<std::chrono::milliseconds>(sysTime);
518 return fromMSecsSinceEpoch(timeInMSec.time_since_epoch().count(),
Qt::UTC);
524 static QDateTime fromStdTimePoint(
const std::chrono::local_time<std::chrono::milliseconds> &
time)
526 return fromStdLocalTime(
time);
530 static QDateTime fromStdLocalTime(
const std::chrono::local_time<std::chrono::milliseconds> &
time)
533 return result.addMSecs(
time.time_since_epoch().count());
536#if QT_CONFIG(timezone) && (__cpp_lib_chrono >= 201907L || defined(Q_QDOC))
539 static QDateTime fromStdZonedTime(
const std::chrono::zoned_time<
540 std::chrono::milliseconds,
541 const std::chrono::time_zone *
546 std::chrono::sys_time<std::chrono::milliseconds> toStdSysMilliseconds()
const
548 const std::chrono::milliseconds duration(toMSecsSinceEpoch());
549 return std::chrono::sys_time<std::chrono::milliseconds>(duration);
553 std::chrono::sys_seconds toStdSysSeconds()
const
555 const std::chrono::seconds duration(toSecsSinceEpoch());
556 return std::chrono::sys_seconds(duration);
562 return std::chrono::milliseconds(rhs.
msecsTo(lhs));
577 *
this = addMSecs(duration.count());
588 *
this = addMSecs(-duration.count());
598#if QT_CORE_REMOVED_SINCE(6, 7)
606 {
return lhs.equals(rhs); }
611#ifndef QT_NO_DATASTREAM
616#if !defined(QT_NO_DEBUG_STREAM) && QT_CONFIG(datestring)
622#ifndef QT_NO_DATASTREAM
631#if !defined(QT_NO_DEBUG_STREAM) && QT_CONFIG(datestring)
643#if QT_CONFIG(datestring) && QT_CORE_INLINE_IMPL_SINCE(6, 7)
The QCalendar class describes calendar systems.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
QDateTime & operator+=(std::chrono::milliseconds duration)
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.
friend QDateTime operator+(const QDateTime &dateTime, std::chrono::milliseconds duration)
friend bool comparesEqual(const QDateTime &lhs, const QDateTime &rhs)
QDateTime addDuration(std::chrono::milliseconds msecs) const
QDateTime & operator-=(std::chrono::milliseconds duration)
friend QDateTime operator+(std::chrono::milliseconds duration, const QDateTime &dateTime)
static qint64 currentMSecsSinceEpoch() noexcept
static QDateTime currentDateTime(const QTimeZone &zone)
friend QDateTime operator-(const QDateTime &dateTime, std::chrono::milliseconds duration)
friend std::chrono::milliseconds operator-(const QDateTime &lhs, const QDateTime &rhs)
void swap(QDateTime &other) noexcept
\inmodule QtCore \reentrant
constexpr bool isValid() const
Returns true if this date is valid; otherwise returns false.
constexpr qint64 toJulianDay() const
Converts the date to a Julian day.
static constexpr QDate fromJulianDay(qint64 jd_)
Converts the Julian day jd to a QDate.
friend constexpr Qt::strong_ordering compareThreeWay(const QDate &lhs, const QDate &rhs) noexcept
constexpr bool isNull() const
Returns true if the date is null; otherwise returns false.
static QDate currentDate()
Returns the system clock's current date.
constexpr QDate()
Constructs a null date.
friend constexpr bool comparesEqual(const QDate &lhs, const QDate &rhs) noexcept
static constexpr int DefaultTwoDigitBaseYear
\macro QT_RESTRICTED_CAST_FROM_ASCII
\inmodule QtCore \reentrant
constexpr bool isNull() const
Returns true if the time is null (i.e., the QTime object was constructed using the default constructo...
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
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,...
friend constexpr bool comparesEqual(const QTime &lhs, const QTime &rhs) noexcept
constexpr int msecsSinceStartOfDay() const
Returns the number of msecs since the start of the day, i.e.
constexpr QTime()
Constructs a null time object.
\inmodule QtCore \title Classes and helpers for defining comparison operators \keyword qtcompare
\variable Qt::strong_ordering::less
Combined button and popup list for selecting options.
constexpr Qt::strong_ordering compareThreeWay(LeftInt lhs, RightInt rhs) noexcept
std::chrono::duration< IntRep, std::ratio< 86400 > > days
#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_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)
GLdouble GLdouble GLdouble GLdouble top
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat h
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
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
QStringView qToStringViewIgnoringNull(const QStringLike &s) noexcept
#define QT_DEPRECATED_VERSION_X_6_9(text)
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Qt::weak_ordering compareThreeWay(const QUrl &lhs, const QUrl &rhs)
char * toString(const MyType &t)
[31]