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 "ui/base/l10n/time_format.h" | 5 #include "ui/base/l10n/time_format.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 const int hours = (delta + half_hour).InHours() % 24; | 102 const int hours = (delta + half_hour).InHours() % 24; |
103 formatter->Format(Formatter::TWO_UNITS_DAY_HOUR, | 103 formatter->Format(Formatter::TWO_UNITS_DAY_HOUR, |
104 days, hours, &time_string); | 104 days, hours, &time_string); |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 const int capacity = time_string.length() + 1; | 108 const int capacity = time_string.length() + 1; |
109 DCHECK_GT(capacity, 1); | 109 DCHECK_GT(capacity, 1); |
110 base::string16 result; | 110 base::string16 result; |
111 UErrorCode error = U_ZERO_ERROR; | 111 UErrorCode error = U_ZERO_ERROR; |
112 time_string.extract(static_cast<UChar*>(WriteInto(&result, capacity)), | 112 time_string.extract(static_cast<UChar*>(base::WriteInto(&result, capacity)), |
113 capacity, error); | 113 capacity, error); |
114 DCHECK(U_SUCCESS(error)); | 114 DCHECK(U_SUCCESS(error)); |
115 return result; | 115 return result; |
116 } | 116 } |
117 | 117 |
118 // static | 118 // static |
119 base::string16 TimeFormat::RelativeDate( | 119 base::string16 TimeFormat::RelativeDate( |
120 const Time& time, | 120 const Time& time, |
121 const Time* optional_midnight_today) { | 121 const Time* optional_midnight_today) { |
122 Time midnight_today = optional_midnight_today ? *optional_midnight_today : | 122 Time midnight_today = optional_midnight_today ? *optional_midnight_today : |
123 Time::Now().LocalMidnight(); | 123 Time::Now().LocalMidnight(); |
124 TimeDelta day = TimeDelta::FromMicroseconds(Time::kMicrosecondsPerDay); | 124 TimeDelta day = TimeDelta::FromMicroseconds(Time::kMicrosecondsPerDay); |
125 Time tomorrow = midnight_today + day; | 125 Time tomorrow = midnight_today + day; |
126 Time yesterday = midnight_today - day; | 126 Time yesterday = midnight_today - day; |
127 if (time >= tomorrow) | 127 if (time >= tomorrow) |
128 return base::string16(); | 128 return base::string16(); |
129 else if (time >= midnight_today) | 129 else if (time >= midnight_today) |
130 return l10n_util::GetStringUTF16(IDS_PAST_TIME_TODAY); | 130 return l10n_util::GetStringUTF16(IDS_PAST_TIME_TODAY); |
131 else if (time >= yesterday) | 131 else if (time >= yesterday) |
132 return l10n_util::GetStringUTF16(IDS_PAST_TIME_YESTERDAY); | 132 return l10n_util::GetStringUTF16(IDS_PAST_TIME_YESTERDAY); |
133 return base::string16(); | 133 return base::string16(); |
134 } | 134 } |
135 | 135 |
136 } // namespace ui | 136 } // namespace ui |
OLD | NEW |