From bcc3472aa231d0a65351b73ce9c75f7688be6623 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 21 Mar 2019 14:58:03 +0100 Subject: [PATCH] Add a warning and tidy some trivia An attempt to setSpec(TimeZone) gets treated as setSpec(LocalTime), as the method has no parameter to carry *which* zone; this was done silently, but should be brought to the caller's attention. So warn. Moved a declaration closer to its use, folded an if/else into a single assignment using ?: and removed a fatuous \fn just before the function it desribed. Change-Id: Ia35c87e0ba373675d3ae1e6ef3bf05016c06c48d Reviewed-by: Thiago Macieira --- src/corelib/time/qdatetime.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index d85b76147b8..183bc0f5ef1 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -2420,10 +2420,7 @@ static qint64 qt_mktime(QDate *date, QTime *time, QDateTimePrivate::DaylightStat local.tm_mday = dd; local.tm_mon = mm - 1; local.tm_year = yy - 1900; - if (daylightStatus) - local.tm_isdst = int(*daylightStatus); - else - local.tm_isdst = -1; + local.tm_isdst = daylightStatus ? int(*daylightStatus) : -1; #if defined(Q_OS_WIN) int hh = local.tm_hour; @@ -2791,7 +2788,6 @@ static void refreshDateTime(QDateTimeData &d) const auto spec = extractSpec(status); const qint64 msecs = getMSecs(d); qint64 epochMSecs = 0; - int offsetFromUtc = 0; QDate testDate; QTime testTime; Q_ASSERT(spec == Qt::TimeZone || spec == Qt::LocalTime); @@ -2828,6 +2824,7 @@ static void refreshDateTime(QDateTimeData &d) epochMSecs = localMSecsToEpochMSecs(msecs, &dstStatus, &testDate, &testTime); status = mergeDaylightStatus(status, dstStatus); } + int offsetFromUtc = 0; if (timeToMSecs(testDate, testTime) == msecs) { status |= QDateTimePrivate::ValidDateTime; // Cache the offset to use in offsetFromUtc() @@ -2883,7 +2880,7 @@ static void setTimeSpec(QDateTimeData &d, Qt::TimeSpec spec, int offsetSeconds) spec = Qt::UTC; break; case Qt::TimeZone: - // Use system time zone instead + qWarning("Using TimeZone in setTimeSpec() is unsupported"); // Use system time zone instead spec = Qt::LocalTime; Q_FALLTHROUGH(); case Qt::UTC: @@ -4260,8 +4257,6 @@ qint64 QDateTime::msecsTo(const QDateTime &other) const } /*! - \fn QDateTime QDateTime::toTimeSpec(Qt::TimeSpec spec) const - Returns a copy of this datetime converted to the given time \a spec.