Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Unified Diff: net/ftp/ftp_util.cc

Issue 1120012: Fix the "ls -l" style date parser to correctly guess the year if it is not provided. (Closed)
Patch Set: better comments Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/ftp/ftp_util.h ('k') | net/ftp/ftp_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/ftp/ftp_util.cc
diff --git a/net/ftp/ftp_util.cc b/net/ftp/ftp_util.cc
index 7fa25c32fd084ce6328fcd5900d14bd2f7d79624..ff9aaa9811c6e6475f3f30e4ce5c0a718eba35fd 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;
}
« no previous file with comments | « net/ftp/ftp_util.h ('k') | net/ftp/ftp_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698