summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--tests/auto/corelib/io/io.pro1
-rw-r--r--tests/auto/corelib/io/qfilesystemmetadata/qfilesystemmetadata.pro4
-rw-r--r--tests/auto/corelib/io/qfilesystemmetadata/tst_qfilesystemmetadata.cpp93
6 files changed, 112 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()
diff --git a/tests/auto/corelib/io/io.pro b/tests/auto/corelib/io/io.pro
index 2e7b987e02..c37c060acd 100644
--- a/tests/auto/corelib/io/io.pro
+++ b/tests/auto/corelib/io/io.pro
@@ -11,6 +11,7 @@ SUBDIRS=\
largefile \
qfileinfo \
qfileselector \
+ qfilesystemmetadata \
qfilesystementry \
qfilesystemwatcher \
qiodevice \
diff --git a/tests/auto/corelib/io/qfilesystemmetadata/qfilesystemmetadata.pro b/tests/auto/corelib/io/qfilesystemmetadata/qfilesystemmetadata.pro
new file mode 100644
index 0000000000..a7d50ece43
--- /dev/null
+++ b/tests/auto/corelib/io/qfilesystemmetadata/qfilesystemmetadata.pro
@@ -0,0 +1,4 @@
+CONFIG += testcase parallel_test
+TARGET = tst_qfilesystemmetadata
+QT = core-private testlib
+SOURCES = tst_qfilesystemmetadata.cpp
diff --git a/tests/auto/corelib/io/qfilesystemmetadata/tst_qfilesystemmetadata.cpp b/tests/auto/corelib/io/qfilesystemmetadata/tst_qfilesystemmetadata.cpp
new file mode 100644
index 0000000000..d17dffe830
--- /dev/null
+++ b/tests/auto/corelib/io/qfilesystemmetadata/tst_qfilesystemmetadata.cpp
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QtCore/private/qfilesystemmetadata_p.h>
+
+class tst_QFileSystemMetaData : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void timeSinceEpoch();
+};
+
+#if defined(QT_BUILD_INTERNAL) && defined(QT_SHARED)
+#ifdef Q_OS_WIN
+static FILETIME epochToFileTime(long seconds)
+{
+ const qint64 sec = 10000000;
+ // FILETIME is time in 1e-7s units since 1601's start: epoch is 1970's
+ // start, 369 years (of which 3*24 +69/4 = 89 were leap) later.
+ const qint64 offset = qint64(365 * 369 + 89) * 24 * 3600;
+ const qint64 convert = (offset + seconds) * sec;
+ FILETIME parts;
+ parts.dwHighDateTime = convert >> 32;
+ parts.dwLowDateTime = convert & 0xffffffff;
+ return parts;
+}
+#endif
+
+void tst_QFileSystemMetaData::timeSinceEpoch()
+{
+ // Regression test for QTBUG-48306, used to fail for TZ=Russia/Moscow
+ // Oct 22 2014 6:00 UTC; TZ=Russia/Moscow changed from +4 to +3 on Oct 26.
+ const long afterEpochUtc = 1413957600L;
+ QFileSystemMetaData meta;
+#ifdef Q_OS_WIN
+ WIN32_FIND_DATA data;
+ memset(&data, 0, sizeof(data));
+ data.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
+ /* data.ftLastAccessTime = data.ftLastWriteTime = */
+ data.ftCreationTime = epochToFileTime(afterEpochUtc);
+ meta.fillFromFindData(data);
+#else
+ QT_STATBUF data;
+ memset(&data, 0, sizeof(data));
+ data.st_ctime = afterEpochUtc;
+ meta.fillFromStatBuf(data);
+#endif
+ QCOMPARE(meta.creationTime().toUTC(),
+ QDateTime::fromMSecsSinceEpoch(afterEpochUtc * qint64(1000), Qt::UTC));
+}
+#else // i.e. no Q_AUTOTEST_EXPORT
+void tst_QFileSystemMetaData::timeSinceEpoch()
+{
+ QSKIP("QFileSystemMetaData methods aren't available to test");
+}
+#endif
+QTEST_MAIN(tst_QFileSystemMetaData)
+#include <tst_qfilesystemmetadata.moc>