summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Van Hoof <philip@codeminded.be>2012-08-22 11:12:12 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-08-23 21:43:15 (GMT)
commitd36f83d319823e9c9a4fd939b12e17223413474e (patch)
tree7b7a0f250c047f65894f09fe895397e732e33aa9
parentc3fe37fe18961d3ddb050fc788281eb79bc61d7a (diff)
downloadQt-d36f83d319823e9c9a4fd939b12e17223413474e.zip
Qt-d36f83d319823e9c9a4fd939b12e17223413474e.tar.gz
Qt-d36f83d319823e9c9a4fd939b12e17223413474e.tar.bz2
Parse yearless date strings on leap years during LIST in QFtp
Adapted _q_parseUnixDir to handle yearless date strings during a leap year while performing LIST. Task-number: QTBUG-26911 Change-Id: I3193400a274a896530d45de986ec8fa5b159abb4 Reviewed-by: Shane Kearns <shane.kearns@accenture.com> Reviewed-by: Philip Van Hoof <philip@codeminded.be>
-rw-r--r--src/network/access/qftp.cpp37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/network/access/qftp.cpp b/src/network/access/qftp.cpp
index 029228b..f577b92 100644
--- a/src/network/access/qftp.cpp
+++ b/src/network/access/qftp.cpp
@@ -466,13 +466,22 @@ void QFtpDTP::abortConnection()
socket->abort();
}
-static void _q_fixupDateTime(QDateTime *dateTime)
+static void _q_fixupDateTime(QDateTime *dateTime, bool leapYear = false)
{
// Adjust for future tolerance.
const int futureTolerance = 86400;
if (dateTime->secsTo(QDateTime::currentDateTime()) < -futureTolerance) {
QDate d = dateTime->date();
- d.setYMD(d.year() - 1, d.month(), d.day());
+ if (leapYear) {
+ int prevLeapYear = d.year() - 1;
+
+ while (!QDate::isLeapYear(prevLeapYear))
+ prevLeapYear--;
+
+ d.setYMD(prevLeapYear, d.month(), d.day());
+ } else {
+ d.setYMD(d.year() - 1, d.month(), d.day());
+ }
dateTime->setDate(d);
}
}
@@ -542,6 +551,30 @@ static void _q_parseUnixDir(const QStringList &tokens, const QString &userName,
}
if (dateTime.isValid())
info->setLastModified(dateTime);
+ else if (dateString.startsWith("Feb 29")) {
+
+ // When the current year on the FTP server is a leap year and a
+ // file's last modified date is Feb 29th, and the current day on
+ // the FTP server is also Feb 29th, then the date can be in
+ // formats n==2 or n==4. toDateTime in that case defaults to 1900
+ // for the missing year. Feb 29 1900 is an invalid date and so
+ // wont be parsed. This adds an exception that handles it.
+
+ int recentLeapYear;
+ QString timeString = dateString.mid(7);
+
+ dateTime = QLocale::c().toDateTime(timeString, QLatin1String("hh:mm"));
+
+ recentLeapYear = QDate::currentDate().year();
+
+ while (!QDate::isLeapYear(recentLeapYear))
+ recentLeapYear--;
+
+ dateTime.setDate(QDate(recentLeapYear, 2, 29));
+
+ _q_fixupDateTime(&dateTime, true);
+ info->setLastModified(dateTime);
+ }
// Resolve permissions
int permissions = 0;