Commit ab2c0d45 authored by cira@chromium.org's avatar cira@chromium.org

Change timeType and dateType in i18n date format API into timeStyle and...

Change timeType and dateType in i18n date format API into timeStyle and dateStyle to match the proposal.
I've kept old keys too, until ChromeOS user switches to time/dateStyle.

Fixed regex for matching styles in date and number format.

TEST=i18n.kaziprst.org/datetimeformat.html should show proper results for both timeType and timeStyle.
Review URL: http://codereview.chromium.org/7244008

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8423 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5d8443c4
...@@ -293,34 +293,34 @@ static icu::DateFormat* CreateDateTimeFormat( ...@@ -293,34 +293,34 @@ static icu::DateFormat* CreateDateTimeFormat(
} }
} }
// Extract date type and time type from settings. // Extract date style and time style from settings.
icu::UnicodeString date_type; icu::UnicodeString date_style;
icu::DateFormat::EStyle date_style = icu::DateFormat::kNone; icu::DateFormat::EStyle icu_date_style = icu::DateFormat::kNone;
if (I18NUtils::ExtractStringSetting(settings, "dateType", &date_type)) { if (I18NUtils::ExtractStringSetting(settings, "dateStyle", &date_style)) {
date_style = GetDateTimeStyle(date_type); icu_date_style = GetDateTimeStyle(date_style);
} }
icu::UnicodeString time_type; icu::UnicodeString time_style;
icu::DateFormat::EStyle time_style = icu::DateFormat::kNone; icu::DateFormat::EStyle icu_time_style = icu::DateFormat::kNone;
if (I18NUtils::ExtractStringSetting(settings, "timeType", &time_type)) { if (I18NUtils::ExtractStringSetting(settings, "timeStyle", &time_style)) {
time_style = GetDateTimeStyle(time_type); icu_time_style = GetDateTimeStyle(time_style);
} }
// Try all combinations of date/time types. // Try all combinations of date/time styles.
if (date_style == icu::DateFormat::kNone && if (icu_date_style == icu::DateFormat::kNone &&
time_style == icu::DateFormat::kNone) { icu_time_style == icu::DateFormat::kNone) {
// Return default short date, short // Return default short date, short
return icu::DateFormat::createDateTimeInstance( return icu::DateFormat::createDateTimeInstance(
icu::DateFormat::kShort, icu::DateFormat::kShort, icu_locale); icu::DateFormat::kShort, icu::DateFormat::kShort, icu_locale);
} else if (date_style != icu::DateFormat::kNone && } else if (icu_date_style != icu::DateFormat::kNone &&
time_style != icu::DateFormat::kNone) { icu_time_style != icu::DateFormat::kNone) {
return icu::DateFormat::createDateTimeInstance( return icu::DateFormat::createDateTimeInstance(
date_style, time_style, icu_locale); icu_date_style, icu_time_style, icu_locale);
} else if (date_style != icu::DateFormat::kNone) { } else if (icu_date_style != icu::DateFormat::kNone) {
return icu::DateFormat::createDateInstance(date_style, icu_locale); return icu::DateFormat::createDateInstance(icu_date_style, icu_locale);
} else { } else {
// time_style != icu::DateFormat::kNone // icu_time_style != icu::DateFormat::kNone
return icu::DateFormat::createTimeInstance(time_style, icu_locale); return icu::DateFormat::createTimeInstance(icu_time_style, icu_locale);
} }
} }
......
...@@ -145,9 +145,8 @@ v8Locale.prototype.createCollator = function(settings) { ...@@ -145,9 +145,8 @@ v8Locale.prototype.createCollator = function(settings) {
* @param {Object} locale - locale object to pass to formatter. * @param {Object} locale - locale object to pass to formatter.
* @param {Object} settings - formatting flags: * @param {Object} settings - formatting flags:
* - skeleton * - skeleton
* - dateType * - dateStyle
* - timeType * - timeStyle
* - calendar
* @private * @private
* @constructor * @constructor
*/ */
...@@ -161,25 +160,37 @@ v8Locale.__DateTimeFormat = function(locale, settings) { ...@@ -161,25 +160,37 @@ v8Locale.__DateTimeFormat = function(locale, settings) {
cleanSettings['skeleton'] = settings['skeleton']; cleanSettings['skeleton'] = settings['skeleton'];
} else { } else {
cleanSettings = {}; cleanSettings = {};
if (settings.hasOwnProperty('dateType')) { if (settings.hasOwnProperty('dateStyle')) {
var ds = settings['dateStyle'];
if (!/^(short|medium|long|full)$/.test(ds)) ds = 'short';
cleanSettings['dateStyle'] = ds;
} else if (settings.hasOwnProperty('dateType')) {
// Obsolete. New spec requires dateStyle, but we'll keep this around
// for current users.
// TODO(cira): Remove when all internal users switch to dateStyle.
var dt = settings['dateType']; var dt = settings['dateType'];
if (!/^short|medium|long|full$/.test(dt)) dt = 'short'; if (!/^(short|medium|long|full)$/.test(dt)) dt = 'short';
cleanSettings['dateType'] = dt; cleanSettings['dateStyle'] = dt;
} }
if (settings.hasOwnProperty('timeType')) { if (settings.hasOwnProperty('timeStyle')) {
var ts = settings['timeStyle'];
if (!/^(short|medium|long|full)$/.test(ts)) ts = 'short';
cleanSettings['timeStyle'] = ts;
} else if (settings.hasOwnProperty('timeType')) {
// TODO(cira): Remove when all internal users switch to timeStyle.
var tt = settings['timeType']; var tt = settings['timeType'];
if (!/^short|medium|long|full$/.test(tt)) tt = 'short'; if (!/^(short|medium|long|full)$/.test(tt)) tt = 'short';
cleanSettings['timeType'] = tt; cleanSettings['timeStyle'] = tt;
} }
} }
// Default is to show short date and time. // Default is to show short date and time.
if (!cleanSettings.hasOwnProperty('skeleton') && if (!cleanSettings.hasOwnProperty('skeleton') &&
!cleanSettings.hasOwnProperty('dateType') && !cleanSettings.hasOwnProperty('dateStyle') &&
!cleanSettings.hasOwnProperty('timeType')) { !cleanSettings.hasOwnProperty('timeStyle')) {
cleanSettings = {'dateType': 'short', cleanSettings = {'dateStyle': 'short',
'timeType': 'short'}; 'timeStyle': 'short'};
} }
locale = v8Locale.__createLocaleOrDefault(locale); locale = v8Locale.__createLocaleOrDefault(locale);
...@@ -249,7 +260,7 @@ v8Locale.__NumberFormat = function(locale, settings) { ...@@ -249,7 +260,7 @@ v8Locale.__NumberFormat = function(locale, settings) {
cleanSettings['pattern'] = settings['pattern']; cleanSettings['pattern'] = settings['pattern'];
} else if (settings.hasOwnProperty('style')) { } else if (settings.hasOwnProperty('style')) {
var style = settings['style']; var style = settings['style'];
if (!/^decimal|currency|percent|scientific$/.test(style)) { if (!/^(decimal|currency|percent|scientific)$/.test(style)) {
style = 'decimal'; style = 'decimal';
} }
cleanSettings['style'] = style; cleanSettings['style'] = style;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment