| 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 "base/i18n/time_formatting.h" | 5 #include "base/i18n/time_formatting.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "third_party/icu/source/i18n/unicode/datefmt.h" | 11 #include "third_party/icu/source/i18n/unicode/datefmt.h" |
| 12 #include "third_party/icu/source/i18n/unicode/dtptngen.h" | 12 #include "third_party/icu/source/i18n/unicode/dtptngen.h" |
| 13 #include "third_party/icu/source/i18n/unicode/smpdtfmt.h" | 13 #include "third_party/icu/source/i18n/unicode/smpdtfmt.h" |
| 14 | 14 |
| 15 using base::Time; | 15 namespace base { |
| 16 | |
| 17 namespace { | 16 namespace { |
| 18 | 17 |
| 19 string16 TimeFormat(const icu::DateFormat* formatter, | 18 string16 TimeFormat(const icu::DateFormat* formatter, |
| 20 const Time& time) { | 19 const Time& time) { |
| 21 DCHECK(formatter); | 20 DCHECK(formatter); |
| 22 icu::UnicodeString date_string; | 21 icu::UnicodeString date_string; |
| 23 | 22 |
| 24 formatter->format(static_cast<UDate>(time.ToDoubleT() * 1000), date_string); | 23 formatter->format(static_cast<UDate>(time.ToDoubleT() * 1000), date_string); |
| 25 return string16(date_string.getBuffer(), | 24 return string16(date_string.getBuffer(), |
| 26 static_cast<size_t>(date_string.length())); | 25 static_cast<size_t>(date_string.length())); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 41 if (begin) | 40 if (begin) |
| 42 begin--; | 41 begin--; |
| 43 time_string.removeBetween(begin, ampm_field.getEndIndex()); | 42 time_string.removeBetween(begin, ampm_field.getEndIndex()); |
| 44 } | 43 } |
| 45 return string16(time_string.getBuffer(), | 44 return string16(time_string.getBuffer(), |
| 46 static_cast<size_t>(time_string.length())); | 45 static_cast<size_t>(time_string.length())); |
| 47 } | 46 } |
| 48 | 47 |
| 49 } // namespace | 48 } // namespace |
| 50 | 49 |
| 51 namespace base { | |
| 52 | |
| 53 string16 TimeFormatTimeOfDay(const Time& time) { | 50 string16 TimeFormatTimeOfDay(const Time& time) { |
| 54 // We can omit the locale parameter because the default should match | 51 // We can omit the locale parameter because the default should match |
| 55 // Chrome's application locale. | 52 // Chrome's application locale. |
| 56 scoped_ptr<icu::DateFormat> formatter( | 53 scoped_ptr<icu::DateFormat> formatter( |
| 57 icu::DateFormat::createTimeInstance(icu::DateFormat::kShort)); | 54 icu::DateFormat::createTimeInstance(icu::DateFormat::kShort)); |
| 58 return TimeFormat(formatter.get(), time); | 55 return TimeFormat(formatter.get(), time); |
| 59 } | 56 } |
| 60 | 57 |
| 61 string16 TimeFormatTimeOfDayWithHourClockType(const Time& time, | 58 string16 TimeFormatTimeOfDayWithHourClockType(const Time& time, |
| 62 HourClockType type, | 59 HourClockType type, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 // See http://userguide.icu-project.org/formatparse/datetime for details | 152 // See http://userguide.icu-project.org/formatparse/datetime for details |
| 156 // about the date/time format syntax. | 153 // about the date/time format syntax. |
| 157 if (pattern_unicode.indexOf('a') == -1) { | 154 if (pattern_unicode.indexOf('a') == -1) { |
| 158 return k24HourClock; | 155 return k24HourClock; |
| 159 } else { | 156 } else { |
| 160 return k12HourClock; | 157 return k12HourClock; |
| 161 } | 158 } |
| 162 } | 159 } |
| 163 | 160 |
| 164 } // namespace base | 161 } // namespace base |
| OLD | NEW |