Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2006-2011 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 v8Locale.prototype.createCollator = function(settings) { | 138 v8Locale.prototype.createCollator = function(settings) { |
| 139 return new v8Locale.Collator(this, settings); | 139 return new v8Locale.Collator(this, settings); |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 /** | 142 /** |
| 143 * DateTimeFormat class implements locale-aware date and time formatting. | 143 * DateTimeFormat class implements locale-aware date and time formatting. |
| 144 * Constructor is not part of public API. | 144 * Constructor is not part of public API. |
| 145 * @param {Object} locale - locale object to pass to formatter. | 145 * @param {Object} locale - locale object to pass to formatter. |
| 146 * @param {Object} settings - formatting flags: | 146 * @param {Object} settings - formatting flags: |
| 147 * - skeleton | 147 * - skeleton |
| 148 * - dateType | 148 * - dateStyle |
| 149 * - timeType | 149 * - timeStyle |
| 150 * - calendar | |
| 151 * @private | 150 * @private |
| 152 * @constructor | 151 * @constructor |
| 153 */ | 152 */ |
| 154 v8Locale.__DateTimeFormat = function(locale, settings) { | 153 v8Locale.__DateTimeFormat = function(locale, settings) { |
| 155 native function NativeJSDateTimeFormat(); | 154 native function NativeJSDateTimeFormat(); |
| 156 | 155 |
| 157 settings = v8Locale.__createSettingsOrDefault(settings, {}); | 156 settings = v8Locale.__createSettingsOrDefault(settings, {}); |
| 158 | 157 |
| 159 var cleanSettings = {}; | 158 var cleanSettings = {}; |
| 160 if (settings.hasOwnProperty('skeleton')) { | 159 if (settings.hasOwnProperty('skeleton')) { |
| 161 cleanSettings['skeleton'] = settings['skeleton']; | 160 cleanSettings['skeleton'] = settings['skeleton']; |
| 162 } else { | 161 } else { |
| 163 cleanSettings = {}; | 162 cleanSettings = {}; |
| 164 if (settings.hasOwnProperty('dateType')) { | 163 if (settings.hasOwnProperty('dateStyle')) { |
| 164 var ds = settings['dateStyle']; | |
| 165 if (!/^short|medium|long|full$/.test(dt)) ds = 'short'; | |
|
rginda
2011/06/23 18:24:16
You'll need to parenthesize that regexp...
/^(sh
Nebojša Ćirić
2011/06/23 18:48:46
Done.
| |
| 166 cleanSettings['dateStyle'] = ds; | |
| 167 } else if (settings.hasOwnProperty('dateType')) { | |
| 168 // Obsolete. New spec requires dateStyle, but we'll keep this around | |
| 169 // for current users. | |
| 170 // TODO(cira): Remove when all internal users switch to dateStyle. | |
| 165 var dt = settings['dateType']; | 171 var dt = settings['dateType']; |
| 166 if (!/^short|medium|long|full$/.test(dt)) dt = 'short'; | 172 if (!/^short|medium|long|full$/.test(dt)) dt = 'short'; |
| 167 cleanSettings['dateType'] = dt; | 173 cleanSettings['dateStyle'] = dt; |
| 168 } | 174 } |
| 169 | 175 |
| 170 if (settings.hasOwnProperty('timeType')) { | 176 if (settings.hasOwnProperty('timeStyle')) { |
| 177 var ts = settings['timeStyle']; | |
| 178 if (!/^short|medium|long|full$/.test(tt)) ts = 'short'; | |
|
rginda
2011/06/23 18:24:16
Here too.
Nebojša Ćirić
2011/06/23 18:48:46
Done.
| |
| 179 cleanSettings['timeStyle'] = ts; | |
| 180 } else if (settings.hasOwnProperty('timeType')) { | |
| 181 // TODO(cira): Remove when all internal users switch to timeStyle. | |
| 171 var tt = settings['timeType']; | 182 var tt = settings['timeType']; |
| 172 if (!/^short|medium|long|full$/.test(tt)) tt = 'short'; | 183 if (!/^short|medium|long|full$/.test(tt)) tt = 'short'; |
| 173 cleanSettings['timeType'] = tt; | 184 cleanSettings['timeStyle'] = tt; |
| 174 } | 185 } |
| 175 } | 186 } |
| 176 | 187 |
| 177 // Default is to show short date and time. | 188 // Default is to show short date and time. |
| 178 if (!cleanSettings.hasOwnProperty('skeleton') && | 189 if (!cleanSettings.hasOwnProperty('skeleton') && |
| 179 !cleanSettings.hasOwnProperty('dateType') && | 190 !cleanSettings.hasOwnProperty('dateStyle') && |
| 180 !cleanSettings.hasOwnProperty('timeType')) { | 191 !cleanSettings.hasOwnProperty('timeStyle')) { |
| 181 cleanSettings = {'dateType': 'short', | 192 cleanSettings = {'dateStyle': 'short', |
| 182 'timeType': 'short'}; | 193 'timeStyle': 'short'}; |
| 183 } | 194 } |
| 184 | 195 |
| 185 locale = v8Locale.__createLocaleOrDefault(locale); | 196 locale = v8Locale.__createLocaleOrDefault(locale); |
| 186 var formatter = NativeJSDateTimeFormat(locale.__icuLocaleID, cleanSettings); | 197 var formatter = NativeJSDateTimeFormat(locale.__icuLocaleID, cleanSettings); |
| 187 | 198 |
| 188 // NativeJSDateTimeFormat creates formatter.options for us, we just need | 199 // NativeJSDateTimeFormat creates formatter.options for us, we just need |
| 189 // to append actual settings to it. | 200 // to append actual settings to it. |
| 190 for (key in cleanSettings) { | 201 for (key in cleanSettings) { |
| 191 formatter.options[key] = cleanSettings[key]; | 202 formatter.options[key] = cleanSettings[key]; |
| 192 } | 203 } |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 * @returns {Object} - v8Locale object. | 371 * @returns {Object} - v8Locale object. |
| 361 * @private | 372 * @private |
| 362 */ | 373 */ |
| 363 v8Locale.__createLocaleOrDefault = function(locale) { | 374 v8Locale.__createLocaleOrDefault = function(locale) { |
| 364 if (!locale || !(locale instanceof v8Locale)) { | 375 if (!locale || !(locale instanceof v8Locale)) { |
| 365 return new v8Locale(); | 376 return new v8Locale(); |
| 366 } else { | 377 } else { |
| 367 return locale; | 378 return locale; |
| 368 } | 379 } |
| 369 }; | 380 }; |
| OLD | NEW |