summaryrefslogtreecommitdiffstats
path: root/net/ftp/ftp_util.cc
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-24 10:35:27 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-24 10:35:27 +0000
commitb7394ff0fd9dc89187d40860e7e86386c373c9ab (patch)
tree3a3b37db268e304d9f867952486a07ce673c778a /net/ftp/ftp_util.cc
parent8ba4973cfcfe2a6b8c0cacca76fabe8b66d41646 (diff)
downloadchromium_src-b7394ff0fd9dc89187d40860e7e86386c373c9ab.zip
chromium_src-b7394ff0fd9dc89187d40860e7e86386c373c9ab.tar.gz
chromium_src-b7394ff0fd9dc89187d40860e7e86386c373c9ab.tar.bz2
Fix the "ls -l" style date parser to correctly guess the year if it is not provided.
Also provide an infrastructure to mock the current time in the tests. BUG=36293 TEST=net_unittests Review URL: http://codereview.chromium.org/1120012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42447 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/ftp/ftp_util.cc')
-rw-r--r--net/ftp/ftp_util.cc23
1 files changed, 17 insertions, 6 deletions
diff --git a/net/ftp/ftp_util.cc b/net/ftp/ftp_util.cc
index 7fa25c3..ff9aaa9 100644
--- a/net/ftp/ftp_util.cc
+++ b/net/ftp/ftp_util.cc
@@ -147,7 +147,9 @@ bool FtpUtil::ThreeLetterMonthToNumber(const string16& text, int* number) {
// static
bool FtpUtil::LsDateListingToTime(const string16& month, const string16& day,
- const string16& rest, base::Time* time) {
+ const string16& rest,
+ const base::Time& current_time,
+ base::Time* result) {
base::Time::Exploded time_exploded = { 0 };
if (!ThreeLetterMonthToNumber(month, &time_exploded.month))
@@ -167,14 +169,23 @@ bool FtpUtil::LsDateListingToTime(const string16& month, const string16& day,
if (!StringToInt(rest.substr(3, 2), &time_exploded.minute))
return false;
- // Use current year.
- base::Time::Exploded now_exploded;
- base::Time::Now().LocalExplode(&now_exploded);
- time_exploded.year = now_exploded.year;
+ // Guess the year.
+ base::Time::Exploded current_exploded;
+ current_time.LocalExplode(&current_exploded);
+
+ // If it's not possible for the parsed date to be in the current year,
+ // use the previous year.
+ if (time_exploded.month > current_exploded.month ||
+ (time_exploded.month == current_exploded.month &&
+ time_exploded.day_of_month > current_exploded.day_of_month)) {
+ time_exploded.year = current_exploded.year - 1;
+ } else {
+ time_exploded.year = current_exploded.year;
+ }
}
// We don't know the time zone of the listing, so just use local time.
- *time = base::Time::FromLocalExploded(time_exploded);
+ *result = base::Time::FromLocalExploded(time_exploded);
return true;
}