QFileSystemEngine/Windows: fix setFileTime when input date is UTC
I was getting a weird 7-hour offset when doing: QVERIFY(file.setFileTime(before.addSecs(-10), QFile::FileModificationTime)); mtime = file.fileTime(QFile::FileModificationTime).toUTC(); QCOMPARE(mtime, before.addSecs(-10)); Change-Id: I35c4da69d754686a43e675b3d215213e448df7cf Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
parent
a3c71b71e2
commit
f77117d6ca
@ -233,6 +233,8 @@ Q_CORE_EXPORT int qt_ntfs_permission_lookup = 0;
|
|||||||
|
|
||||||
static inline bool toFileTime(const QDateTime &date, FILETIME *fileTime)
|
static inline bool toFileTime(const QDateTime &date, FILETIME *fileTime)
|
||||||
{
|
{
|
||||||
|
SYSTEMTIME sTime;
|
||||||
|
if (date.timeSpec() == Qt::LocalTime) {
|
||||||
SYSTEMTIME lTime;
|
SYSTEMTIME lTime;
|
||||||
const QDate d = date.date();
|
const QDate d = date.date();
|
||||||
const QTime t = date.time();
|
const QTime t = date.time();
|
||||||
@ -246,9 +248,22 @@ static inline bool toFileTime(const QDateTime &date, FILETIME *fileTime)
|
|||||||
lTime.wMilliseconds = t.msec();
|
lTime.wMilliseconds = t.msec();
|
||||||
lTime.wDayOfWeek = d.dayOfWeek() % 7;
|
lTime.wDayOfWeek = d.dayOfWeek() % 7;
|
||||||
|
|
||||||
SYSTEMTIME sTime;
|
|
||||||
if (!::TzSpecificLocalTimeToSystemTime(0, &lTime, &sTime))
|
if (!::TzSpecificLocalTimeToSystemTime(0, &lTime, &sTime))
|
||||||
return false;
|
return false;
|
||||||
|
} else {
|
||||||
|
QDateTime utcDate = date.toUTC();
|
||||||
|
const QDate d = utcDate.date();
|
||||||
|
const QTime t = utcDate.time();
|
||||||
|
|
||||||
|
sTime.wYear = d.year();
|
||||||
|
sTime.wMonth = d.month();
|
||||||
|
sTime.wDay = d.day();
|
||||||
|
sTime.wHour = t.hour();
|
||||||
|
sTime.wMinute = t.minute();
|
||||||
|
sTime.wSecond = t.second();
|
||||||
|
sTime.wMilliseconds = t.msec();
|
||||||
|
sTime.wDayOfWeek = d.dayOfWeek() % 7;
|
||||||
|
}
|
||||||
|
|
||||||
return ::SystemTimeToFileTime(&sTime, fileTime);
|
return ::SystemTimeToFileTime(&sTime, fileTime);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user