summaryrefslogtreecommitdiffstats
path: root/src/corelib/time/qdatetime.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/time/qdatetime.h')
-rw-r--r--src/corelib/time/qdatetime.h58
1 files changed, 44 insertions, 14 deletions
diff --git a/src/corelib/time/qdatetime.h b/src/corelib/time/qdatetime.h
index f8a9360fbb..77247dcd07 100644
--- a/src/corelib/time/qdatetime.h
+++ b/src/corelib/time/qdatetime.h
@@ -35,28 +35,28 @@ public:
#if __cpp_lib_chrono >= 201907L || defined(Q_QDOC)
QT_POST_CXX17_API_IN_EXPORTED_CLASS
Q_IMPLICIT constexpr QDate(std::chrono::year_month_day date) noexcept
- : jd(date.ok() ? stdSysDaysToJulianDay(date) : nullJd())
+ : jd(date.ok() ? stdSysDaysToJulianDay(date QT6_CALL_NEW_OVERLOAD_TAIL) : nullJd())
{}
QT_POST_CXX17_API_IN_EXPORTED_CLASS
Q_IMPLICIT constexpr QDate(std::chrono::year_month_day_last date) noexcept
- : jd(date.ok() ? stdSysDaysToJulianDay(date) : nullJd())
+ : jd(date.ok() ? stdSysDaysToJulianDay(date QT6_CALL_NEW_OVERLOAD_TAIL) : nullJd())
{}
QT_POST_CXX17_API_IN_EXPORTED_CLASS
Q_IMPLICIT constexpr QDate(std::chrono::year_month_weekday date) noexcept
- : jd(date.ok() ? stdSysDaysToJulianDay(date) : nullJd())
+ : jd(date.ok() ? stdSysDaysToJulianDay(date QT6_CALL_NEW_OVERLOAD_TAIL) : nullJd())
{}
QT_POST_CXX17_API_IN_EXPORTED_CLASS
Q_IMPLICIT constexpr QDate(std::chrono::year_month_weekday_last date) noexcept
- : jd(date.ok() ? stdSysDaysToJulianDay(date) : nullJd())
+ : jd(date.ok() ? stdSysDaysToJulianDay(date QT6_CALL_NEW_OVERLOAD_TAIL) : nullJd())
{}
QT_POST_CXX17_API_IN_EXPORTED_CLASS
static constexpr QDate fromStdSysDays(const std::chrono::sys_days &days) noexcept
{
- return QDate(stdSysDaysToJulianDay(days));
+ return QDate(stdSysDaysToJulianDay(days QT6_CALL_NEW_OVERLOAD_TAIL));
}
QT_POST_CXX17_API_IN_EXPORTED_CLASS
@@ -177,7 +177,9 @@ private:
static constexpr inline qint64 unixEpochJd() { return Q_INT64_C(2440588); }
#if __cpp_lib_chrono >= 201907L
- static constexpr qint64 stdSysDaysToJulianDay(const std::chrono::sys_days &days) noexcept
+ QT_POST_CXX17_API_IN_EXPORTED_CLASS
+ static constexpr qint64
+ stdSysDaysToJulianDay(const std::chrono::sys_days &days QT6_DECL_NEW_OVERLOAD_TAIL) noexcept
{
const auto epochDays = days.time_since_epoch().count();
// minJd() and maxJd() fit into 40 bits.
@@ -189,6 +191,13 @@ private:
}
return unixEpochJd() + epochDays;
}
+
+#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
+ static constexpr qint64 stdSysDaysToJulianDay(const std::chrono::sys_days &days) noexcept
+ {
+ return stdSysDaysToJulianDay(days QT6_CALL_NEW_OVERLOAD_TAIL);
+ }
+#endif // QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
#endif // __cpp_lib_chrono >= 201907L
qint64 jd;
@@ -302,7 +311,7 @@ class Q_CORE_EXPORT QDateTime
quintptr status : 8;
# endif
#endif
- friend constexpr bool operator==(const ShortData &lhs, const ShortData &rhs)
+ friend constexpr bool operator==(ShortData lhs, ShortData rhs)
{ return lhs.status == rhs.status && lhs.msecs == rhs.msecs; }
};
@@ -499,8 +508,26 @@ public:
NSDate *toNSDate() const Q_DECL_NS_RETURNS_AUTORELEASED;
#endif
+ static QDateTime fromStdTimePoint(
+ std::chrono::time_point<
+ std::chrono::system_clock,
+ std::chrono::milliseconds
+ > time
+ );
+
#if __cpp_lib_chrono >= 201907L || defined(Q_QDOC)
#if __cpp_concepts >= 201907L || defined(Q_QDOC)
+private:
+ // The duration type of the result of a clock_cast<system_clock>.
+ // This duration may differ from the duration of the input.
+ template <typename Clock, typename Duration>
+ using system_clock_cast_duration = decltype(
+ std::chrono::clock_cast<std::chrono::system_clock>(
+ std::declval<const std::chrono::time_point<Clock, Duration> &>()
+ ).time_since_epoch()
+ );
+
+public:
// Generic clock, as long as it's compatible with us (= system_clock)
template <typename Clock, typename Duration>
static QDateTime fromStdTimePoint(const std::chrono::time_point<Clock, Duration> &time)
@@ -508,14 +535,17 @@ public:
requires(const std::chrono::time_point<Clock, Duration> &t) {
// the clock can be converted to system_clock
std::chrono::clock_cast<std::chrono::system_clock>(t);
- // the duration can be converted to milliseconds
- requires std::is_convertible_v<Duration, std::chrono::milliseconds>;
+ // after the conversion to system_clock, the duration type
+ // we get is convertible to milliseconds
+ requires std::is_convertible_v<
+ system_clock_cast_duration<Clock, Duration>,
+ std::chrono::milliseconds
+ >;
}
{
- const auto sysTime = std::chrono::clock_cast<std::chrono::system_clock>(time);
- // clock_cast can change the duration, so convert it again to milliseconds
- const auto timeInMSec = std::chrono::time_point_cast<std::chrono::milliseconds>(sysTime);
- return fromMSecsSinceEpoch(timeInMSec.time_since_epoch().count(), Qt::UTC);
+ using namespace std::chrono;
+ const sys_time<milliseconds> sysTime = clock_cast<system_clock>(time);
+ return fromStdTimePoint(sysTime);
}
#endif // __cpp_concepts
@@ -529,7 +559,7 @@ public:
QT_POST_CXX17_API_IN_EXPORTED_CLASS
static QDateTime fromStdLocalTime(const std::chrono::local_time<std::chrono::milliseconds> &time)
{
- QDateTime result(QDate(1970, 1, 1), QTime(0, 0, 0));
+ QDateTime result(QDate(1970, 1, 1), QTime(0, 0, 0), TransitionResolution::LegacyBehavior);
return result.addMSecs(time.time_since_epoch().count());
}