| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/ftp/ftp_util.h" | 5 #include "net/ftp/ftp_util.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/i18n/case_conversion.h" | 10 #include "base/i18n/case_conversion.h" |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 if (time_exploded.month > current_exploded.month || | 279 if (time_exploded.month > current_exploded.month || |
| 280 (time_exploded.month == current_exploded.month && | 280 (time_exploded.month == current_exploded.month && |
| 281 time_exploded.day_of_month > current_exploded.day_of_month)) { | 281 time_exploded.day_of_month > current_exploded.day_of_month)) { |
| 282 time_exploded.year = current_exploded.year - 1; | 282 time_exploded.year = current_exploded.year - 1; |
| 283 } else { | 283 } else { |
| 284 time_exploded.year = current_exploded.year; | 284 time_exploded.year = current_exploded.year; |
| 285 } | 285 } |
| 286 } | 286 } |
| 287 | 287 |
| 288 // We don't know the time zone of the listing, so just use local time. | 288 // We don't know the time zone of the listing, so just use local time. |
| 289 *result = base::Time::FromLocalExploded(time_exploded); | 289 if (!base::Time::FromLocalExploded(time_exploded, result)) { |
| 290 return false; |
| 291 } |
| 290 return true; | 292 return true; |
| 291 } | 293 } |
| 292 | 294 |
| 293 // static | 295 // static |
| 294 bool FtpUtil::WindowsDateListingToTime(const base::string16& date, | 296 bool FtpUtil::WindowsDateListingToTime(const base::string16& date, |
| 295 const base::string16& time, | 297 const base::string16& time, |
| 296 base::Time* result) { | 298 base::Time* result) { |
| 297 base::Time::Exploded time_exploded = { 0 }; | 299 base::Time::Exploded time_exploded = { 0 }; |
| 298 | 300 |
| 299 // Date should be in format MM-DD-YY[YY]. | 301 // Date should be in format MM-DD-YY[YY]. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 if (time_exploded.hour < 12) | 343 if (time_exploded.hour < 12) |
| 342 time_exploded.hour += 12; | 344 time_exploded.hour += 12; |
| 343 } else if (base::EqualsASCII(am_or_pm, "AM")) { | 345 } else if (base::EqualsASCII(am_or_pm, "AM")) { |
| 344 if (time_exploded.hour == 12) | 346 if (time_exploded.hour == 12) |
| 345 time_exploded.hour = 0; | 347 time_exploded.hour = 0; |
| 346 } else { | 348 } else { |
| 347 return false; | 349 return false; |
| 348 } | 350 } |
| 349 } | 351 } |
| 350 | 352 |
| 351 // We don't know the time zone of the server, so just use local time. | 353 // We don't know the time zone of the listing, so just use local time. |
| 352 *result = base::Time::FromLocalExploded(time_exploded); | 354 if (!base::Time::FromLocalExploded(time_exploded, result)) { |
| 355 return false; |
| 356 } |
| 353 return true; | 357 return true; |
| 354 } | 358 } |
| 355 | 359 |
| 356 // static | 360 // static |
| 357 base::string16 FtpUtil::GetStringPartAfterColumns(const base::string16& text, | 361 base::string16 FtpUtil::GetStringPartAfterColumns(const base::string16& text, |
| 358 int columns) { | 362 int columns) { |
| 359 base::i18n::UTF16CharIterator iter(&text); | 363 base::i18n::UTF16CharIterator iter(&text); |
| 360 | 364 |
| 361 for (int i = 0; i < columns; i++) { | 365 for (int i = 0; i < columns; i++) { |
| 362 // Skip the leading whitespace. | 366 // Skip the leading whitespace. |
| 363 while (!iter.end() && u_isspace(iter.get())) | 367 while (!iter.end() && u_isspace(iter.get())) |
| 364 iter.Advance(); | 368 iter.Advance(); |
| 365 | 369 |
| 366 // Skip the actual text of i-th column. | 370 // Skip the actual text of i-th column. |
| 367 while (!iter.end() && !u_isspace(iter.get())) | 371 while (!iter.end() && !u_isspace(iter.get())) |
| 368 iter.Advance(); | 372 iter.Advance(); |
| 369 } | 373 } |
| 370 | 374 |
| 371 base::string16 result(text.substr(iter.array_pos())); | 375 base::string16 result(text.substr(iter.array_pos())); |
| 372 base::TrimWhitespace(result, base::TRIM_ALL, &result); | 376 base::TrimWhitespace(result, base::TRIM_ALL, &result); |
| 373 return result; | 377 return result; |
| 374 } | 378 } |
| 375 | 379 |
| 376 } // namespace net | 380 } // namespace net |
| OLD | NEW |