Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Unified Diff: content/renderer/date_time_formatter.cc

Issue 15057004: Week picker for android (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/date_time_formatter.cc
diff --git a/content/renderer/date_time_formatter.cc b/content/renderer/date_time_formatter.cc
index 1adb0debddf9fa2f5c44f7af58be0f8e25aa9665..6b00e4647cbc62a30cb00bab198a542693d5d347 100644
--- a/content/renderer/date_time_formatter.cc
+++ b/content/renderer/date_time_formatter.cc
@@ -25,6 +25,7 @@ void DateTimeFormatter::CreatePatternMap() {
patterns_[ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL] = "yyyy-MM-dd'T'HH:mm";
patterns_[ui::TEXT_INPUT_TYPE_MONTH] = "yyyy-MM";
patterns_[ui::TEXT_INPUT_TYPE_TIME] = "HH:mm";
+ patterns_[ui::TEXT_INPUT_TYPE_WEEK] = "Y-'W'ww";
}
DateTimeFormatter::DateTimeFormatter(
@@ -41,14 +42,17 @@ DateTimeFormatter::DateTimeFormatter(
DateTimeFormatter::DateTimeFormatter(
ui::TextInputType type,
- int year, int month, int day, int hour, int minute, int second)
+ int year, int month, int day, int hour, int minute, int second,
+ int week_year, int week)
: type_(type),
year_(year),
month_(month),
day_(day),
hour_(hour),
minute_(minute),
- second_(second) {
+ second_(second),
+ week_year_(week_year),
+ week_(week) {
CreatePatternMap();
pattern_ = type_ > 0 && type_ <= ui::TEXT_INPUT_TYPE_MAX ?
&patterns_[type_] : &patterns_[ui::TEXT_INPUT_TYPE_NONE];
@@ -83,6 +87,14 @@ int DateTimeFormatter::GetSecond() const {
return second_;
}
+int DateTimeFormatter::GetWeekYear() const {
+ return week_year_;
+}
+
+int DateTimeFormatter::GetWeek() const {
+ return week_;
+}
+
ui::TextInputType DateTimeFormatter::GetType() const {
return type_;
}
@@ -94,13 +106,26 @@ const std::string& DateTimeFormatter::GetFormattedValue() const {
const std::string DateTimeFormatter::FormatString() const {
UErrorCode success = U_ZERO_ERROR;
if (year_ == 0 && month_ == 0 && day_ == 0 &&
- hour_ == 0 && minute_ == 0 && second_ == 0) {
+ hour_ == 0 && minute_ == 0 && second_ == 0 &&
+ week_year_ == 0 && week_ == 0) {
return std::string();
}
std::string result;
- const icu::GregorianCalendar calendar(
- year_, month_, day_, hour_, minute_, second_, success);
+ icu::GregorianCalendar calendar(success);
+ if (type_ == ui::TEXT_INPUT_TYPE_WEEK) {
Miguel Garcia 2013/05/10 15:17:59 you probably want to check that success is still t
keishi 2013/05/14 13:47:47 Done.
+ calendar.setMinimalDaysInFirstWeek(4);
Miguel Garcia 2013/05/10 15:17:59 I think some comment on why this is needed would b
keishi 2013/05/14 13:47:47 Done.
+ calendar.setFirstDayOfWeek(UCAL_MONDAY);
Miguel Garcia 2013/05/10 15:17:59 Doesn't this depend on the locale?
keishi 2013/05/14 13:47:47 ISO weeks always start from Monday regardless of l
+ calendar.set(UCAL_YEAR_WOY, week_year_);
+ calendar.set(UCAL_WEEK_OF_YEAR, week_);
+ } else {
Miguel Garcia 2013/05/10 15:17:59 it seems you can anyway set year, month... in all
keishi 2013/05/14 13:47:47 I may not be understanding you correctly. Are you
Miguel Garcia 2013/05/17 11:23:38 I'm still hesitant to special case week here, can
keishi 2013/05/22 07:33:26 calendar.getTime() will return milliseconds since
Miguel Garcia 2013/05/23 18:38:49 Ok, I think you've convinced me :) On 2013/05/22
+ calendar.set(UCAL_YEAR, year_);
+ calendar.set(UCAL_MONTH, month_);
+ calendar.set(UCAL_DATE, day_);
+ calendar.set(UCAL_HOUR_OF_DAY, hour_);
+ calendar.set(UCAL_MINUTE, minute_);
+ calendar.set(UCAL_SECOND, second_);
+ }
if (success <= U_ZERO_ERROR) {
UDate time = calendar.getTime(success);
icu::SimpleDateFormat formatter(*pattern_, success);
@@ -135,6 +160,8 @@ void DateTimeFormatter::ExtractType(
type_ = ui::TEXT_INPUT_TYPE_TIME;
break;
case WebKit::WebDateTimeInputTypeWeek: // Not implemented
+ type_ = ui::TEXT_INPUT_TYPE_WEEK;
+ break;
case WebKit::WebDateTimeInputTypeNone:
default:
type_ = ui::TEXT_INPUT_TYPE_NONE;
@@ -176,6 +203,8 @@ bool DateTimeFormatter::ParseValues() {
hour_ = ExtractValue(cal, UCAL_HOUR_OF_DAY); // 24h format
minute_ = ExtractValue(cal, UCAL_MINUTE);
second_ = ExtractValue(cal, UCAL_SECOND);
+ week_year_ = ExtractValue(cal, UCAL_YEAR_WOY);
+ week_ = ExtractValue(cal, UCAL_WEEK_OF_YEAR);
}
}
@@ -189,6 +218,8 @@ void DateTimeFormatter::ClearAll() {
hour_ = 0;
minute_ = 0;
second_ = 0;
+ week_year_ = 0;
+ week_ = 0;
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698