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 "chrome/common/time_format.h" | 5 #include "chrome/common/time_format.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 // Anything bigger gets "X days left" | 289 // Anything bigger gets "X days left" |
290 } else { | 290 } else { |
291 number = static_cast<int>(delta.ToInternalValue() / | 291 number = static_cast<int>(delta.ToInternalValue() / |
292 Time::kMicrosecondsPerDay); | 292 Time::kMicrosecondsPerDay); |
293 time_string = formatters[3]->format(number, error); | 293 time_string = formatters[3]->format(number, error); |
294 } | 294 } |
295 | 295 |
296 // With the fallback added, this should never fail. | 296 // With the fallback added, this should never fail. |
297 DCHECK(U_SUCCESS(error)); | 297 DCHECK(U_SUCCESS(error)); |
298 int capacity = time_string.length() + 1; | 298 int capacity = time_string.length() + 1; |
| 299 DCHECK_GT(capacity, 1); |
299 string16 result; | 300 string16 result; |
300 time_string.extract(static_cast<UChar*>( | 301 time_string.extract(static_cast<UChar*>(WriteInto(&result, capacity)), |
301 WriteInto(&result, capacity)), | |
302 capacity, error); | 302 capacity, error); |
303 DCHECK(U_SUCCESS(error)); | 303 DCHECK(U_SUCCESS(error)); |
304 return result; | 304 return result; |
305 } | 305 } |
306 | 306 |
307 // static | 307 // static |
308 string16 TimeFormat::TimeElapsed(const TimeDelta& delta) { | 308 string16 TimeFormat::TimeElapsed(const TimeDelta& delta) { |
309 return FormatTimeImpl(delta, FORMAT_ELAPSED); | 309 return FormatTimeImpl(delta, FORMAT_ELAPSED); |
310 } | 310 } |
311 | 311 |
(...skipping 16 matching lines...) Expand all Loading... |
328 | 328 |
329 // Filter out "today" and "yesterday" | 329 // Filter out "today" and "yesterday" |
330 if (time >= midnight_today) | 330 if (time >= midnight_today) |
331 return l10n_util::GetStringUTF16(IDS_PAST_TIME_TODAY); | 331 return l10n_util::GetStringUTF16(IDS_PAST_TIME_TODAY); |
332 else if (time >= midnight_today - | 332 else if (time >= midnight_today - |
333 TimeDelta::FromMicroseconds(Time::kMicrosecondsPerDay)) | 333 TimeDelta::FromMicroseconds(Time::kMicrosecondsPerDay)) |
334 return l10n_util::GetStringUTF16(IDS_PAST_TIME_YESTERDAY); | 334 return l10n_util::GetStringUTF16(IDS_PAST_TIME_YESTERDAY); |
335 | 335 |
336 return string16(); | 336 return string16(); |
337 } | 337 } |
OLD | NEW |