QDateTime::fromStdTimePoint: fix a call to fromMSecsSinceEpoch
The overload taking a Qt::TimeSpec is deprecated; we need to use the one taking a QTimeZone instead. However I can't just use QTimeZone because this is inline code in qdatetime.h, and QTimeZone is only forward declared there. Moving the definition in qtimezone.h is possible (like it's done for zoned_time), but that is a source break (requires a new inclusion from users) and also weird (this function doesn't deal with timezones, why do we need to include qtimezone.h?). Instead, just add another overload of fromStdTimePoint that takes precisely sys_time<milliseconds>. As such, it can be always available even in C++17, and implemented out-of-line. Even if this is a new symbol, the new commit policy allows the backport. I also don't think this qualifies as a new feature; it's a cleanup that we forgot to do (if we had a C++20-enabled configuration in the CI when we also did the fromMSecsSinceEpoch deprecation, we would've caught this). Pick-to: 6.7 6.5 Change-Id: Ica77da291be4bcda2ffc7c164316a2977974c386 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
12d45d049a
commit
c4fc3a74b4
@ -5350,7 +5350,7 @@ QDateTime QDateTime::currentDateTimeUtc()
|
||||
\since 6.4
|
||||
|
||||
Constructs a datetime representing the same point in time as \a time,
|
||||
using Qt::UTC as its specification.
|
||||
using Qt::UTC as its time representation.
|
||||
|
||||
The clock of \a time must be compatible with
|
||||
\c{std::chrono::system_clock}; in particular, a conversion
|
||||
@ -5369,6 +5369,22 @@ QDateTime QDateTime::currentDateTimeUtc()
|
||||
\sa toStdSysMilliseconds(), fromMSecsSinceEpoch()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\since 6.4
|
||||
\overload
|
||||
|
||||
Constructs a datetime representing the same point in time as \a time,
|
||||
using Qt::UTC as its time representation.
|
||||
*/
|
||||
QDateTime QDateTime::fromStdTimePoint(
|
||||
std::chrono::time_point<
|
||||
std::chrono::system_clock,
|
||||
std::chrono::milliseconds
|
||||
> time)
|
||||
{
|
||||
return fromMSecsSinceEpoch(time.time_since_epoch().count(), QTimeZone::UTC);
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QDateTime QDateTime::fromStdTimePoint(const std::chrono::local_time<std::chrono::milliseconds> &time)
|
||||
\since 6.4
|
||||
|
@ -508,6 +508,13 @@ 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:
|
||||
@ -539,7 +546,7 @@ public:
|
||||
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);
|
||||
return fromStdTimePoint(timeInMSec);
|
||||
}
|
||||
#endif // __cpp_concepts
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user