| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/renderer/date_time_formatter.h" | 5 #include "content/renderer/date_time_formatter.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h" | 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDateTimeChooserPar
ams.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDateTimeChooserPar
ams.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 } | 88 } |
| 89 | 89 |
| 90 const std::string& DateTimeFormatter::GetFormattedValue() const { | 90 const std::string& DateTimeFormatter::GetFormattedValue() const { |
| 91 return formatted_string_; | 91 return formatted_string_; |
| 92 } | 92 } |
| 93 | 93 |
| 94 const std::string DateTimeFormatter::FormatString() const { | 94 const std::string DateTimeFormatter::FormatString() const { |
| 95 UErrorCode success = U_ZERO_ERROR; | 95 UErrorCode success = U_ZERO_ERROR; |
| 96 if (year_ == 0 && month_ == 0 && day_ == 0 && | 96 if (year_ == 0 && month_ == 0 && day_ == 0 && |
| 97 hour_ == 0 && minute_ == 0 && second_ == 0) { | 97 hour_ == 0 && minute_ == 0 && second_ == 0) { |
| 98 return ""; | 98 return std::string(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 std::string result; | 101 std::string result; |
| 102 const icu::GregorianCalendar calendar( | 102 const icu::GregorianCalendar calendar( |
| 103 year_, month_, day_, hour_, minute_, second_, success); | 103 year_, month_, day_, hour_, minute_, second_, success); |
| 104 if (success <= U_ZERO_ERROR) { | 104 if (success <= U_ZERO_ERROR) { |
| 105 UDate time = calendar.getTime(success); | 105 UDate time = calendar.getTime(success); |
| 106 icu::SimpleDateFormat formatter(*pattern_, success); | 106 icu::SimpleDateFormat formatter(*pattern_, success); |
| 107 icu::UnicodeString formatted_time; | 107 icu::UnicodeString formatted_time; |
| 108 formatter.format(time, formatted_time, success); | 108 formatter.format(time, formatted_time, success); |
| 109 UTF16ToUTF8(formatted_time.getBuffer(), | 109 UTF16ToUTF8(formatted_time.getBuffer(), |
| 110 static_cast<size_t>(formatted_time.length()), | 110 static_cast<size_t>(formatted_time.length()), |
| 111 &result); | 111 &result); |
| 112 if (success <= U_ZERO_ERROR) | 112 if (success <= U_ZERO_ERROR) |
| 113 return result; | 113 return result; |
| 114 } | 114 } |
| 115 LOG(WARNING) << "Calendar not created: error " << success; | 115 LOG(WARNING) << "Calendar not created: error " << success; |
| 116 return ""; | 116 return std::string(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void DateTimeFormatter::ExtractType( | 119 void DateTimeFormatter::ExtractType( |
| 120 const WebKit::WebDateTimeChooserParams& source) { | 120 const WebKit::WebDateTimeChooserParams& source) { |
| 121 switch (source.type) { | 121 switch (source.type) { |
| 122 case WebKit::WebDateTimeInputTypeDate: | 122 case WebKit::WebDateTimeInputTypeDate: |
| 123 type_ = ui::TEXT_INPUT_TYPE_DATE; | 123 type_ = ui::TEXT_INPUT_TYPE_DATE; |
| 124 break; | 124 break; |
| 125 case WebKit::WebDateTimeInputTypeDateTime: | 125 case WebKit::WebDateTimeInputTypeDateTime: |
| 126 type_ = ui::TEXT_INPUT_TYPE_DATE_TIME; | 126 type_ = ui::TEXT_INPUT_TYPE_DATE_TIME; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 void DateTimeFormatter::ClearAll() { | 185 void DateTimeFormatter::ClearAll() { |
| 186 year_ = 0; | 186 year_ = 0; |
| 187 month_ = 0; | 187 month_ = 0; |
| 188 day_ = 0; | 188 day_ = 0; |
| 189 hour_ = 0; | 189 hour_ = 0; |
| 190 minute_ = 0; | 190 minute_ = 0; |
| 191 second_ = 0; | 191 second_ = 0; |
| 192 } | 192 } |
| 193 | 193 |
| 194 } // namespace content | 194 } // namespace content |
| OLD | NEW |