summaryrefslogtreecommitdiffstats
path: root/src
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
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')
-rw-r--r--src/corelib/io/qfileinfo.cpp18
-rw-r--r--src/corelib/io/qfilesystemengine_win.cpp12
-rw-r--r--src/corelib/io/qfilesystemmetadata_p.h2
3 files changed, 14 insertions, 18 deletions
diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp
index 5acee25d02..12fd7d3048 100644
--- a/src/corelib/io/qfileinfo.cpp
+++ b/src/corelib/io/qfileinfo.cpp
@@ -1295,7 +1295,7 @@ qint64 QFileInfo::size() const
}
/*!
- Returns the date and time when the file was created.
+ Returns the date and local time when the file was created.
On most Unix systems, this function returns the time of the last
status change. A status change occurs when the file is created,
@@ -1316,13 +1316,13 @@ QDateTime QFileInfo::created() const
if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::CreationTime))
if (!QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::CreationTime))
return QDateTime();
- return d->metaData.creationTime();
+ return d->metaData.creationTime().toLocalTime();
}
- return d->getFileTime(QAbstractFileEngine::CreationTime);
+ return d->getFileTime(QAbstractFileEngine::CreationTime).toLocalTime();
}
/*!
- Returns the date and time when the file was last modified.
+ Returns the date and local time when the file was last modified.
\sa created(), lastRead()
*/
@@ -1335,13 +1335,13 @@ QDateTime QFileInfo::lastModified() const
if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::ModificationTime))
if (!QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::ModificationTime))
return QDateTime();
- return d->metaData.modificationTime();
+ return d->metaData.modificationTime().toLocalTime();
}
- return d->getFileTime(QAbstractFileEngine::ModificationTime);
+ return d->getFileTime(QAbstractFileEngine::ModificationTime).toLocalTime();
}
/*!
- Returns the date and time when the file was last read (accessed).
+ Returns the date and local time when the file was last read (accessed).
On platforms where this information is not available, returns the
same as lastModified().
@@ -1357,9 +1357,9 @@ QDateTime QFileInfo::lastRead() const
if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::AccessTime))
if (!QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::AccessTime))
return QDateTime();
- return d->metaData.accessTime();
+ return d->metaData.accessTime().toLocalTime();
}
- return d->getFileTime(QAbstractFileEngine::AccessTime);
+ return d->getFileTime(QAbstractFileEngine::AccessTime).toLocalTime();
}
/*!
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
diff --git a/src/corelib/io/qfilesystemmetadata_p.h b/src/corelib/io/qfilesystemmetadata_p.h
index 091552f86e..b09223d656 100644
--- a/src/corelib/io/qfilesystemmetadata_p.h
+++ b/src/corelib/io/qfilesystemmetadata_p.h
@@ -68,7 +68,7 @@ QT_BEGIN_NAMESPACE
class QFileSystemEngine;
-class QFileSystemMetaData
+class Q_AUTOTEST_EXPORT QFileSystemMetaData
{
public:
QFileSystemMetaData()