8#include <QtCore/qcalendar.h>
9#include <QtCore/qnamespace.h>
10#include <QtCore/qshareddata.h>
11#include <QtCore/qstring.h>
16#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
28 explicit constexpr QDate(
qint64 julianDay) : jd(julianDay) {}
30 constexpr QDate() : jd(nullJd()) {}
33#if __cpp_lib_chrono >= 201907L || defined(Q_QDOC)
40 *
this = fromStdSysDays(ymd);
49 *
this = fromStdSysDays(ymdl);
58 *
this = fromStdSysDays(ymw);
67 *
this = fromStdSysDays(ymwl);
71 static QDate fromStdSysDays(
const std::chrono::sys_days &days)
73 const QDate epoch(unixEpochJd());
74 return epoch.addDays(
days.time_since_epoch().count());
78 std::chrono::sys_days toStdSysDays()
const
80 const QDate epoch(unixEpochJd());
81 return std::chrono::sys_days(std::chrono::days(epoch.daysTo(*
this)));
85 constexpr bool isNull()
const {
return !isValid(); }
86 constexpr bool isValid()
const {
return jd >= minJd() && jd <= maxJd(); }
92 int dayOfWeek()
const;
93 int dayOfYear()
const;
94 int daysInMonth()
const;
95 int daysInYear()
const;
96 int weekNumber(
int *yearNum =
nullptr)
const;
106#if QT_DEPRECATED_SINCE(6, 9)
108 QDateTime startOfDay(
Qt::TimeSpec spec,
int offsetSeconds = 0) const;
110 QDateTime endOfDay(
Qt::TimeSpec spec,
int offsetSeconds = 0) const;
118#if QT_CONFIG(datestring)
124 bool setDate(
int year,
int month,
int day);
125 bool setDate(
int year,
int month,
int day,
QCalendar cal);
127 void getDate(
int *year,
int *month,
int *day)
const;
130#if __cpp_lib_chrono >= 201907L || defined(Q_QDOC)
132 [[nodiscard]]
QDate addDuration(std::chrono::days days)
const
134 return addDays(
days.count());
139 [[nodiscard]]
QDate addYears(
int years)
const;
145#if QT_CONFIG(datestring)
156 static bool isValid(
int y,
int m,
int d);
157 static bool isLeapYear(
int year);
160 {
return jd_ >= minJd() && jd_ <= maxJd() ?
QDate(jd_) :
QDate() ; }
165 static constexpr inline qint64 nullJd() {
return (std::numeric_limits<qint64>::min)(); }
166 static constexpr inline qint64 minJd() {
return Q_INT64_C(-784350574879); }
167 static constexpr inline qint64 maxJd() {
return Q_INT64_C( 784354017364); }
168 static constexpr inline qint64 unixEpochJd() {
return Q_INT64_C(2440588); }
181#ifndef QT_NO_DATASTREAM
190 explicit constexpr QTime(
int ms) : mds(ms)
195 QTime(
int h,
int m,
int s = 0,
int ms = 0);
197 constexpr bool isNull()
const {
return mds == NullTime; }
198 bool isValid()
const;
204#if QT_CONFIG(datestring)
210 bool setHMS(
int h,
int m,
int s,
int ms = 0);
212 [[nodiscard]]
QTime addSecs(
int secs)
const;
213 int secsTo(
QTime t)
const;
214 [[nodiscard]]
QTime addMSecs(
int ms)
const;
221#if QT_CONFIG(datestring)
231 static bool isValid(
int h,
int m,
int s,
int ms = 0);
234 enum TimeFlag { NullTime = -1 };
235 constexpr inline int ds()
const {
return mds == -1 ? 0 : mds; }
247#ifndef QT_NO_DATASTREAM
259#if QT_VERSION >= QT_VERSION_CHECK(7,0,0) || defined(QT_BOOTSTRAPPED)
260# if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
265# if Q_BYTE_ORDER == Q_BIG_ENDIAN
269# if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
273 qintptr msecs :
sizeof(
void *) * 8 - 8;
275# if Q_BYTE_ORDER == Q_BIG_ENDIAN
280 {
return lhs.status == rhs.status && lhs.msecs == rhs.msecs; }
287 static constexpr bool CanBeSmall =
sizeof(
ShortData) * 8 > 50;
300 bool isShort()
const;
313#if QT_DEPRECATED_SINCE(6, 9)
323 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(
QDateTime)
329 bool isValid()
const;
334 int offsetFromUtc()
const;
336#if QT_CONFIG(timezone)
339 QString timeZoneAbbreviation()
const;
340 bool isDaylightTime()
const;
342 qint64 toMSecsSinceEpoch()
const;
343 qint64 toSecsSinceEpoch()
const;
347#if QT_DEPRECATED_SINCE(6, 9)
349 void setTimeSpec(
Qt::TimeSpec spec);
351 void setOffsetFromUtc(
int offsetSeconds);
353 void setTimeZone(
const QTimeZone &toZone);
354 void setMSecsSinceEpoch(
qint64 msecs);
355 void setSecsSinceEpoch(
qint64 secs);
357#if QT_CONFIG(datestring)
365 [[nodiscard]]
QDateTime addYears(
int years)
const;
370 return addMSecs(msecs.count());
373#if QT_DEPRECATED_SINCE(6, 9)
379 QDateTime toOffsetFromUtc(
int offsetSeconds)
const;
389#if QT_CONFIG(datestring)
403#if QT_DEPRECATED_SINCE(6, 9)
405 static
QDateTime fromMSecsSinceEpoch(
qint64 msecs,
Qt::TimeSpec spec,
int offsetFromUtc = 0);
407 static
QDateTime fromSecsSinceEpoch(
qint64 secs,
Qt::TimeSpec spec,
int offsetFromUtc = 0);
416 static
qint64 currentSecsSinceEpoch() noexcept;
418#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
425#if __cpp_lib_chrono >= 201907L || defined(Q_QDOC)
426#if __cpp_concepts >= 201907L || defined(Q_QDOC)
428 template <
typename Clock,
typename Duration>
429 static QDateTime fromStdTimePoint(
const std::chrono::time_point<Clock, Duration> &
time)
431 requires(
const std::chrono::time_point<Clock, Duration> &
t) {
433 std::chrono::clock_cast<std::chrono::system_clock>(
t);
435 requires std::is_convertible_v<Duration, std::chrono::milliseconds>;
438 const auto sysTime = std::chrono::clock_cast<std::chrono::system_clock>(
time);
440 const auto timeInMSec = std::chrono::time_point_cast<std::chrono::milliseconds>(sysTime);
441 return fromMSecsSinceEpoch(timeInMSec.time_since_epoch().count(),
Qt::UTC);
447 static QDateTime fromStdTimePoint(
const std::chrono::local_time<std::chrono::milliseconds> &
time)
449 return fromStdLocalTime(
time);
453 static QDateTime fromStdLocalTime(
const std::chrono::local_time<std::chrono::milliseconds> &
time)
456 return result.addMSecs(
time.time_since_epoch().count());
459#if QT_CONFIG(timezone) && (__cpp_lib_chrono >= 201907L || defined(Q_QDOC))
462 static QDateTime fromStdZonedTime(
const std::chrono::zoned_time<
463 std::chrono::milliseconds,
464 const std::chrono::time_zone *
469 std::chrono::sys_time<std::chrono::milliseconds> toStdSysMilliseconds()
const
471 const std::chrono::milliseconds duration(toMSecsSinceEpoch());
472 return std::chrono::sys_time<std::chrono::milliseconds>(duration);
476 std::chrono::sys_seconds toStdSysSeconds()
const
478 const std::chrono::seconds duration(toSecsSinceEpoch());
479 return std::chrono::sys_seconds(duration);
485 return std::chrono::milliseconds(rhs.
msecsTo(lhs));
500 *
this = addMSecs(duration.count());
511 *
this = addMSecs(-duration.count());
533#ifndef QT_NO_DATASTREAM
538#if !defined(QT_NO_DEBUG_STREAM) && QT_CONFIG(datestring)
544#ifndef QT_NO_DATASTREAM
553#if !defined(QT_NO_DEBUG_STREAM) && QT_CONFIG(datestring)
The QCalendar class describes calendar systems.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
friend bool operator>(const QDateTime &lhs, const QDateTime &rhs)
Returns true if lhs is later than rhs; otherwise returns false.
friend bool operator<=(const QDateTime &lhs, const QDateTime &rhs)
Returns true if lhs is earlier than or equal to rhs; otherwise returns false.
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...
friend bool operator!=(const QDateTime &lhs, const QDateTime &rhs)
Returns true if lhs is different from rhs; otherwise returns false.
friend bool operator>=(const QDateTime &lhs, const QDateTime &rhs)
Returns true if lhs is later than or equal to rhs; otherwise returns false.
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)
QDateTime addDuration(std::chrono::milliseconds msecs) const
friend bool operator==(const QDateTime &lhs, const QDateTime &rhs)
Returns true if lhs is the same as rhs; otherwise returns false.
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 bool operator<(const QDateTime &lhs, const QDateTime &rhs)
Returns true if lhs is earlier than rhs; otherwise returns false.
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.
constexpr bool isNull() const
Returns true if the date is null; otherwise returns false.
friend constexpr bool operator!=(QDate lhs, QDate rhs)
Returns true if lhs and rhs represent distinct days; otherwise returns false.
friend constexpr bool operator>=(QDate lhs, QDate rhs)
Returns true if lhs is later than or equal to rhs; otherwise returns false.
static QDate currentDate()
Returns the system clock's current date.
constexpr QDate()
Constructs a null date.
friend constexpr bool operator<=(QDate lhs, QDate rhs)
Returns true if lhs is earlier than or equal to rhs; otherwise returns false.
friend constexpr bool operator==(QDate lhs, QDate rhs)
Returns true if lhs and rhs represent the same day, otherwise false.
\macro QT_RESTRICTED_CAST_FROM_ASCII
\inmodule QtCore \reentrant
friend constexpr bool operator<=(QTime lhs, QTime rhs)
Returns true if lhs is earlier than or equal to rhs; otherwise returns false.
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 bool operator==(QTime lhs, QTime rhs)
Returns true if lhs is equal to rhs; otherwise returns false.
friend constexpr bool operator!=(QTime lhs, QTime rhs)
Returns true if lhs is different from rhs; otherwise returns false.
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,...
constexpr int msecsSinceStartOfDay() const
Returns the number of msecs since the start of the day, i.e.
friend constexpr bool operator>=(QTime lhs, QTime rhs)
Returns true if lhs is later than or equal to rhs; otherwise returns false.
constexpr QTime()
Constructs a null time object.
Combined button and popup list for selecting options.
std::chrono::duration< IntRep, std::ratio< 86400 > > days
#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)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat h
bool operator>(const QPoint &a, const QPoint &b)
static bool fromString(const QMetaObject *mo, QString s, Allocate &&allocate)
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
static bool operator<(const QSettingsIniKey &k1, const QSettingsIniKey &k2)
QStringView qToStringViewIgnoringNull(const QStringLike &s) noexcept
#define QT_DEPRECATED_VERSION_X_6_9(text)
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
char * toString(const MyType &t)
[31]