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 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_RENDERER_DATE_TIME_FORMATTER_H_ 6 #define CONTENT_RENDERER_DATE_TIME_FORMATTER_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "content/common/content_export.h" 12 #include "third_party/icu/source/common/unicode/unistr.h" 13 #include "third_party/icu/source/i18n/unicode/gregocal.h" 14 #include "ui/base/ime/text_input_type.h" 15 16 namespace WebKit { 17 struct WebDateTimeChooserParams; 18 } // namespace WebKit 19 20 namespace content { 21 22 // Converts between a text string representing a date/time and 23 // a set of year/month/day/hour/minute/second and vice versa. 24 // It is timezone agnostic. 25 class CONTENT_EXPORT DateTimeFormatter { 26 public: 27 explicit DateTimeFormatter(const WebKit::WebDateTimeChooserParams& source); 28 DateTimeFormatter( 29 ui::TextInputType type, 30 int year, int month, int day, int hour, int minute, int second, 31 int week_year, int week); 32 ~DateTimeFormatter(); 33 34 int GetYear() const; 35 int GetMonth() const; 36 int GetDay() const; 37 int GetHour() const; 38 int GetMinute() const; 39 int GetSecond() const; 40 int GetWeekYear() const; 41 int GetWeek() const; 42 ui::TextInputType GetType() const; 43 const std::string& GetFormattedValue() const; 44 45 private: 46 void CreatePatternMap(); 47 bool ParseValues(); 48 const std::string FormatString() const; 49 int ExtractValue( 50 const icu::Calendar* calendar, UCalendarDateFields value) const; 51 void ExtractType(const WebKit::WebDateTimeChooserParams& source); 52 void ClearAll(); 53 54 ui::TextInputType type_; 55 icu::UnicodeString patterns_[ui::TEXT_INPUT_TYPE_MAX + 1]; 56 int year_; 57 int month_; 58 int day_; 59 int hour_; 60 int minute_; 61 int second_; 62 int week_year_; 63 int week_; 64 const icu::UnicodeString* pattern_; 65 std::string formatted_string_; 66 67 DISALLOW_COPY_AND_ASSIGN(DateTimeFormatter); 68 }; 69 70 } // namespace content 71 72 #endif // CONTENT_RENDERER_DATE_TIME_FORMATTER_H_ 73