Index: net/ftp/ftp_util.cc |
diff --git a/net/ftp/ftp_util.cc b/net/ftp/ftp_util.cc |
index 0f384bd31ee98f056a8e40c57cc84d02fee66d77..553d513f52752d26946fadd357ffa2f9a02a78e5 100644 |
--- a/net/ftp/ftp_util.cc |
+++ b/net/ftp/ftp_util.cc |
@@ -12,6 +12,7 @@ |
#include "base/logging.h" |
#include "base/memory/singleton.h" |
#include "base/string_number_conversions.h" |
+#include "base/string_split.h" |
#include "base/string_tokenizer.h" |
#include "base/string_util.h" |
#include "base/time.h" |
@@ -255,6 +256,67 @@ bool FtpUtil::LsDateListingToTime(const string16& month, const string16& day, |
} |
// static |
+bool FtpUtil::WindowsDateListingToTime(const string16& date, |
eroman
2011/08/10 23:52:16
I didn't review this, I presume it is just a move.
Paweł Hajdan Jr.
2011/08/11 00:03:19
Not really, I changed it a bit to make AM/PM optio
|
+ const string16& time, |
+ base::Time* result) { |
+ base::Time::Exploded time_exploded = { 0 }; |
+ |
+ // Date should be in format MM-DD-YY[YY]. |
+ std::vector<string16> date_parts; |
+ base::SplitString(date, '-', &date_parts); |
+ if (date_parts.size() != 3) |
+ return false; |
+ if (!base::StringToInt(date_parts[0], &time_exploded.month)) |
+ return false; |
+ if (!base::StringToInt(date_parts[1], &time_exploded.day_of_month)) |
+ return false; |
+ if (!base::StringToInt(date_parts[2], &time_exploded.year)) |
+ return false; |
+ if (time_exploded.year < 0) |
+ return false; |
+ // If year has only two digits then assume that 00-79 is 2000-2079, |
+ // and 80-99 is 1980-1999. |
+ if (time_exploded.year < 80) |
+ time_exploded.year += 2000; |
+ else if (time_exploded.year < 100) |
+ time_exploded.year += 1900; |
+ |
+ // Time should be in format HH:MM[(AM|PM)] |
+ if (time.length() < 5) |
+ return false; |
+ |
+ std::vector<string16> time_parts; |
+ base::SplitString(time.substr(0, 5), ':', &time_parts); |
+ if (time_parts.size() != 2) |
+ return false; |
+ if (!base::StringToInt(time_parts[0], &time_exploded.hour)) |
+ return false; |
+ if (!base::StringToInt(time_parts[1], &time_exploded.minute)) |
+ return false; |
+ if (!time_exploded.HasValidValues()) |
+ return false; |
+ |
+ if (time.length() > 5) { |
+ if (time.length() != 7) |
+ return false; |
+ string16 am_or_pm(time.substr(5, 2)); |
+ if (EqualsASCII(am_or_pm, "PM")) { |
+ if (time_exploded.hour < 12) |
+ time_exploded.hour += 12; |
+ } else if (EqualsASCII(am_or_pm, "AM")) { |
+ if (time_exploded.hour == 12) |
+ time_exploded.hour = 0; |
+ } else { |
+ return false; |
+ } |
+ } |
+ |
+ // We don't know the time zone of the server, so just use local time. |
+ *result = base::Time::FromLocalExploded(time_exploded); |
+ return true; |
+} |
+ |
+// static |
string16 FtpUtil::GetStringPartAfterColumns(const string16& text, int columns) { |
base::i18n::UTF16CharIterator iter(&text); |