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(ds)) ds = 'short'; | |
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(ts)) ts = 'short'; | |
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; |
jungshik at Google
2011/06/24 16:33:47
given that this will go away later, I wouldn't say
Nebojša Ćirić
2011/06/24 16:43:22
I am not going to refactor - current code makes it
| |
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 var cleanSettings = {}; | 253 var cleanSettings = {}; |
243 if (settings.hasOwnProperty('skeleton')) { | 254 if (settings.hasOwnProperty('skeleton')) { |
244 // Assign skeleton to cleanSettings and fix invalid currency pattern | 255 // Assign skeleton to cleanSettings and fix invalid currency pattern |
245 // if present - 'ooxo' becomes 'o'. | 256 // if present - 'ooxo' becomes 'o'. |
246 cleanSettings['skeleton'] = | 257 cleanSettings['skeleton'] = |
247 settings['skeleton'].replace(/\u00a4+[^\u00a4]+\u00a4+/g, '\u00a4'); | 258 settings['skeleton'].replace(/\u00a4+[^\u00a4]+\u00a4+/g, '\u00a4'); |
248 } else if (settings.hasOwnProperty('pattern')) { | 259 } else if (settings.hasOwnProperty('pattern')) { |
249 cleanSettings['pattern'] = settings['pattern']; | 260 cleanSettings['pattern'] = settings['pattern']; |
250 } else if (settings.hasOwnProperty('style')) { | 261 } else if (settings.hasOwnProperty('style')) { |
251 var style = settings['style']; | 262 var style = settings['style']; |
252 if (!/^decimal|currency|percent|scientific$/.test(style)) { | 263 if (!/^(decimal|currency|percent|scientific)$/.test(style)) { |
253 style = 'decimal'; | 264 style = 'decimal'; |
254 } | 265 } |
255 cleanSettings['style'] = style; | 266 cleanSettings['style'] = style; |
256 } | 267 } |
257 | 268 |
258 // Default is to show decimal style. | 269 // Default is to show decimal style. |
259 if (!cleanSettings.hasOwnProperty('skeleton') && | 270 if (!cleanSettings.hasOwnProperty('skeleton') && |
260 !cleanSettings.hasOwnProperty('pattern') && | 271 !cleanSettings.hasOwnProperty('pattern') && |
261 !cleanSettings.hasOwnProperty('style')) { | 272 !cleanSettings.hasOwnProperty('style')) { |
262 cleanSettings = {'style': 'decimal'}; | 273 cleanSettings = {'style': 'decimal'}; |
(...skipping 97 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 |