summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qfilesystemengine_win.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2016-12-14 11:18:50 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2017-01-11 11:53:27 +0000
commit4b4bd6ab981fd92de05efdaeda6914e18b6c4c9a (patch)
treef7d688ce7d13ce1bb273aa29cd3f0a1d68b9a1d8 /src/corelib/io/qfilesystemengine_win.cpp
parent80bbaf6fad7376a94bc460eb6e98031bb5266ce1 (diff)
Simplify fileTimeToQDateTime() by having it return a UTC time
This avoids so many complications. The prior code, using SystemTimeToTzSpecificLocalTime(), lead to unhelpful results when the QDateTime() implementation used MS-POSIX's defective mktime(). Although SystemTimeToTzSpecificLocalTime() is actually more correct, we were getting inconsistent results by mixing the two: and eliminating the use of mktime() turns out to be decidedly tricky. So, to avoid inconsistency, stick with a UTC time (which is what FILETIME is defined as). Change QFileInfo's methods to explicitly convert .toLocalTime() where appropriate and document that these methods do indeed return local time (as we conjecture has been taken for granted by callers). Also added a regression test for the reported case of this going wrong. A time-stamp from before Russia's (permanent, not DST) change of TZ could end up inconsistently handled between file-system meta-data and raw date-time APIs, due to cross-talk between different MS-Win time APIs. [ChangeLog][QtCore][QFileInfo] Made sure that all file lifecycle times are in local time. This was probably true before, but is now explicit. Task-number: QTBUG-48306 Change-Id: Ic0b99d25c4168f623d31967bc60665c0c4f38a14 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qfilesystemengine_win.cpp')
-rw-r--r--src/corelib/io/qfilesystemengine_win.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/corelib/io/qfilesystemengine_win.cpp b/src/corelib/io/qfilesystemengine_win.cpp
index 663d9cd61d..ee54c5fd3a 100644
--- a/src/corelib/io/qfilesystemengine_win.cpp
+++ b/src/corelib/io/qfilesystemengine_win.cpp
@@ -1368,15 +1368,11 @@ bool QFileSystemEngine::setPermissions(const QFileSystemEntry &entry, QFile::Per
static inline QDateTime fileTimeToQDateTime(const FILETIME *time)
{
- QDateTime ret;
-
- SYSTEMTIME sTime, lTime;
+ SYSTEMTIME sTime;
FileTimeToSystemTime(time, &sTime);
- SystemTimeToTzSpecificLocalTime(0, &sTime, &lTime);
- ret.setDate(QDate(lTime.wYear, lTime.wMonth, lTime.wDay));
- ret.setTime(QTime(lTime.wHour, lTime.wMinute, lTime.wSecond, lTime.wMilliseconds));
-
- return ret;
+ return QDateTime(QDate(sTime.wYear, sTime.wMonth, sTime.wDay),
+ QTime(sTime.wHour, sTime.wMinute, sTime.wSecond, sTime.wMilliseconds),
+ Qt::UTC);
}
QDateTime QFileSystemMetaData::creationTime() const