Fix/adapt the uses of {to,set,from}Time_t in the qtbase source code

Move those to the equivalent {to,set,from}SecsSinceEpoch(), except for
the cases that did QDateTime::currentDateTime{,Utc}().toTime_t. Those
are best implemented with QDateTime::currentSecsSinceEpoch().

Change-Id: Ib57b52598e2f452985e9fffd145a366c92cfda20
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
bb10
Thiago Macieira 2016-06-21 14:27:48 -07:00
parent 829e421ddc
commit 9e49778380
17 changed files with 36 additions and 40 deletions

View File

@ -86,7 +86,7 @@ QByteArray ConnectionManager::clientId() const
{
if (id.isEmpty()) {
// Generate peer id
int startupTime = int(QDateTime::currentDateTime().toTime_t());
qint64 startupTime = QDateTime::currentSecsSinceEpoch();
id += QString::asprintf("-QT%04x-", (QT_VERSION % 0xffff00) >> 8).toLatin1();
id += QByteArray::number(startupTime, 10);

View File

@ -141,7 +141,7 @@ bool MetaInfo::parse(const QByteArray &data)
}
if (dict.contains("creation date"))
metaInfoCreationDate.setTime_t(dict.value("creation date").toInt());
metaInfoCreationDate.setSecsSinceEpoch(dict.value("creation date").toInt());
if (dict.contains("comment"))
metaInfoComment = QString::fromUtf8(dict.value("comment").toByteArray());
if (dict.contains("created by"))

View File

@ -703,7 +703,7 @@ void TorrentClient::connectToPeers()
// Pick a random peer from the list of weighed peers.
TorrentPeer *peer = weighedPeers.takeAt(qrand() % weighedPeers.size());
weighedPeers.removeAll(peer);
peer->connectStart = QDateTime::currentDateTime().toTime_t();
peer->connectStart = QDateTime::currentSecsSinceEpoch();
peer->lastVisited = peer->connectStart;
// Connect to the peer.
@ -717,7 +717,7 @@ QList<TorrentPeer *> TorrentClient::weighedFreePeers() const
QList<TorrentPeer *> weighedPeers;
// Generate a list of peers that we want to connect to.
uint now = QDateTime::currentDateTime().toTime_t();
qint64 now = QDateTime::currentSecsSinceEpoch();
QList<TorrentPeer *> freePeers;
QMap<QString, int> connectionsPerPeer;
foreach (TorrentPeer *peer, d->peers) {

View File

@ -91,7 +91,7 @@ public:
: QEventTransition(this, QEvent::Timer)
{
setTargetState(target);
qsrand((uint)QDateTime::currentDateTime().toTime_t());
qsrand((uint)QDateTime::currentSecsSinceEpoch());
startTimer(1000);
}

View File

@ -290,7 +290,7 @@ void CompositionRenderer::updateCirclePos()
if (m_current_object != NoObject)
return;
QDateTime dt = QDateTime::currentDateTime();
qreal t = (dt.toTime_t() * 1000 + dt.time().msec()) / 1000.0;
qreal t = dt.toMSecsSinceEpoch() / 1000.0;
qreal x = width() / qreal(2) + (qCos(t*8/11) + qSin(-t)) * width() / qreal(4);
qreal y = height() / qreal(2) + (qSin(t*6/7) + qCos(t * qreal(1.5))) * height() / qreal(4);

View File

@ -181,7 +181,7 @@ static QCFType<CFPropertyListRef> macValue(const QVariant &value)
QDateTime dt = value.toDateTime();
if (dt.timeSpec() == Qt::LocalTime) {
QDateTime reference;
reference.setTime_t((uint)kCFAbsoluteTimeIntervalSince1970);
reference.setSecsSinceEpoch(qint64(kCFAbsoluteTimeIntervalSince1970));
result = CFDateCreate(kCFAllocatorDefault, CFAbsoluteTime(reference.secsTo(dt)));
} else {
goto string_case;
@ -293,7 +293,7 @@ static QVariant qtValue(CFPropertyListRef cfvalue)
return map;
} else if (typeId == CFDateGetTypeID()) {
QDateTime dt;
dt.setTime_t((uint)kCFAbsoluteTimeIntervalSince1970);
dt.setSecsSinceEpoch(qint64(kCFAbsoluteTimeIntervalSince1970));
return dt.addSecs((int)CFDateGetAbsoluteTime(static_cast<CFDateRef>(cfvalue)));
}
return QVariant();

View File

@ -969,7 +969,7 @@ QUuid QUuid::createUuid()
{
int *pseed = new int;
static QBasicAtomicInt serial = Q_BASIC_ATOMIC_INITIALIZER(2);
qsrand(*pseed = QDateTime::currentDateTimeUtc().toTime_t()
qsrand(*pseed = QDateTime::currentSecsSinceEpoch()
+ quintptr(&pseed)
+ serial.fetchAndAddRelaxed(1));
uuidseed.setLocalData(pseed);
@ -977,7 +977,7 @@ QUuid QUuid::createUuid()
#else
static bool seeded = false;
if (!seeded)
qsrand(QDateTime::currentDateTimeUtc().toSecsSinceEpoch()
qsrand(QDateTime::currentSecsSinceEpoch()
+ quintptr(&seeded));
#endif

View File

@ -770,7 +770,7 @@ bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConvers
QFileInfo info(fileName);
QString key = QLatin1String("qt_pixmap")
% info.absoluteFilePath()
% HexString<uint>(info.lastModified().toTime_t())
% HexString<uint>(info.lastModified().toSecsSinceEpoch())
% HexString<quint64>(info.size())
% HexString<uint>(data ? data->pixelType() : QPlatformPixmap::PixmapType);

View File

@ -970,7 +970,7 @@ QList<QNetworkCookie> QNetworkCookiePrivate::parseSetCookieHeaderLine(const QByt
if (ok) {
if (secs <= 0) {
//earliest representable time (RFC6265 section 5.2.2)
cookie.setExpirationDate(QDateTime::fromTime_t(0));
cookie.setExpirationDate(QDateTime::fromSecsSinceEpoch(0));
} else {
cookie.setExpirationDate(now.addSecs(secs));
}

View File

@ -522,36 +522,36 @@ bool QNetworkReplyHttpImplPrivate::loadFromCacheIfAllowed(QHttpNetworkRequest &h
* now
* is the current (local) time
*/
int age_value = 0;
qint64 age_value = 0;
it = cacheHeaders.findRawHeader("age");
if (it != cacheHeaders.rawHeaders.constEnd())
age_value = it->second.toInt();
age_value = it->second.toLongLong();
QDateTime dateHeader;
int date_value = 0;
qint64 date_value = 0;
it = cacheHeaders.findRawHeader("date");
if (it != cacheHeaders.rawHeaders.constEnd()) {
dateHeader = QNetworkHeadersPrivate::fromHttpDate(it->second);
date_value = dateHeader.toTime_t();
date_value = dateHeader.toSecsSinceEpoch();
}
int now = currentDateTime.toTime_t();
int request_time = now;
int response_time = now;
qint64 now = currentDateTime.toSecsSinceEpoch();
qint64 request_time = now;
qint64 response_time = now;
// Algorithm from RFC 2616 section 13.2.3
int apparent_age = qMax(0, response_time - date_value);
int corrected_received_age = qMax(apparent_age, age_value);
int response_delay = response_time - request_time;
int corrected_initial_age = corrected_received_age + response_delay;
int resident_time = now - response_time;
int current_age = corrected_initial_age + resident_time;
qint64 apparent_age = qMax<qint64>(0, response_time - date_value);
qint64 corrected_received_age = qMax(apparent_age, age_value);
qint64 response_delay = response_time - request_time;
qint64 corrected_initial_age = corrected_received_age + response_delay;
qint64 resident_time = now - response_time;
qint64 current_age = corrected_initial_age + resident_time;
int freshness_lifetime = 0;
qint64 freshness_lifetime = 0;
// RFC 2616 13.2.4 Expiration Calculations
if (lastModified.isValid() && dateHeader.isValid()) {
int diff = lastModified.secsTo(dateHeader);
qint64 diff = lastModified.secsTo(dateHeader);
freshness_lifetime = diff / 10;
if (httpRequest.headerField("Warning").isEmpty()) {
QDateTime dt = currentDateTime.addSecs(current_age);

View File

@ -1271,14 +1271,10 @@ static QByteArray qEncodeNtlmv2Response(const QAuthenticatorPrivate *ctx,
if(timeArray.size()) {
ds.writeRawData(timeArray.constData(), timeArray.size());
} else {
QDateTime currentTime(QDate::currentDate(),
QTime::currentTime(), Qt::UTC);
// number of seconds between 1601 and epoc(1970)
// number of seconds between 1601 and the epoch (1970)
// 369 years, 89 leap years
// ((369 * 365) + 89) * 24 * 3600 = 11644473600
time = Q_UINT64_C(currentTime.toTime_t() + 11644473600);
time = QDateTime::currentSecsSinceEpoch() + 11644473600;
// represented as 100 nano seconds
time = Q_UINT64_C(time * 10000000);

View File

@ -285,7 +285,7 @@ quint64 QNetworkSessionPrivateImpl::bytesReceived() const
quint64 QNetworkSessionPrivateImpl::activeTime() const
{
if (state == QNetworkSession::Connected && startTime != Q_UINT64_C(0))
return QDateTime::currentDateTimeUtc().toTime_t() - startTime;
return QDateTime::currentSecsSinceEpoch() - startTime;
return Q_UINT64_C(0);
}

View File

@ -141,7 +141,7 @@ inline bool qIsLikelyToBeNfs(int /* handle */)
static QString seedAndTemplate()
{
qsrand(QDateTime::currentDateTimeUtc().toTime_t());
qsrand(QDateTime::currentSecsSinceEpoch());
return QDir::tempPath() + "/tst_qfileinfo-XXXXXX";
}

View File

@ -116,7 +116,7 @@ Q_CONSTRUCTOR_FUNCTION(initializeLang)
static QString seedAndTemplate()
{
qsrand(QDateTime::currentDateTimeUtc().toTime_t());
qsrand(QDateTime::currentSecsSinceEpoch());
return QDir::tempPath() + "/tst_qmimedatabase-XXXXXX";
}

View File

@ -145,8 +145,8 @@ tst_QLocale::tst_QLocale()
qRegisterMetaType<QLocale::FormatType>("QLocale::FormatType");
// Test if in Central European Time zone
uint x1 = QDateTime(QDate(1990, 1, 1), QTime()).toTime_t();
uint x2 = QDateTime(QDate(1990, 6, 1), QTime()).toTime_t();
uint x1 = QDateTime(QDate(1990, 1, 1), QTime()).toSecsSinceEpoch();
uint x2 = QDateTime(QDate(1990, 6, 1), QTime()).toSecsSinceEpoch();
europeanTimeZone = (x1 == 631148400 && x2 == 644191200);
}

View File

@ -1818,7 +1818,7 @@ void tst_QDBusAbstractAdaptor::typeMatching_data()
LLDateTimeMap lldtmap;
lldtmap[-1] = QDateTime();
QDateTime now = QDateTime::currentDateTime();
lldtmap[now.toTime_t()] = now; // array of struct of int64 and struct of 3 ints and struct of 4 ints and int
lldtmap[now.toSecsSinceEpoch()] = now; // array of struct of int64 and struct of 3 ints and struct of 4 ints and int
QTest::newRow("lldtmap") << "LLDateTimeMap" << "a{x((iii)(iiii)i)}" << QVariant::fromValue(lldtmap);
MyStruct s;

View File

@ -539,7 +539,7 @@ void tst_NetworkSelfTest::httpServer()
{
QByteArray uniqueExtension = QByteArray::number((qulonglong)this) +
QByteArray::number((qulonglong)qrand()) +
QByteArray::number((qulonglong)QDateTime::currentDateTime().toTime_t());
QByteArray::number(QDateTime::currentSecsSinceEpoch());
netChat(80, QList<Chat>()
// HTTP/0.9 chat: