| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * DateFormat is for formatting and parsing dates in a locale-sensitive | 6 * DateFormat is for formatting and parsing dates in a locale-sensitive |
| 7 * manner. | 7 * manner. |
| 8 * It allows the user to choose from a set of standard date time formats as well | 8 * It allows the user to choose from a set of standard date time formats as well |
| 9 * as specify a customized pattern under certain locales. Date elements that | 9 * as specify a customized pattern under certain locales. Date elements that |
| 10 * vary across locales include month name, week name, field order, etc. | 10 * vary across locales include month name, week name, field order, etc. |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 * | 177 * |
| 178 * If [locale] does not exist in our set of supported locales then an | 178 * If [locale] does not exist in our set of supported locales then an |
| 179 * [ArgumentError] is thrown. | 179 * [ArgumentError] is thrown. |
| 180 */ | 180 */ |
| 181 DateFormat([String newPattern, String locale]) { | 181 DateFormat([String newPattern, String locale]) { |
| 182 // TODO(alanknight): It should be possible to specify multiple skeletons eg | 182 // TODO(alanknight): It should be possible to specify multiple skeletons eg |
| 183 // date, time, timezone all separately. Adding many or named parameters to | 183 // date, time, timezone all separately. Adding many or named parameters to |
| 184 // the constructor seems awkward, especially with the possibility of | 184 // the constructor seems awkward, especially with the possibility of |
| 185 // confusion with the locale. A "fluent" interface with cascading on an | 185 // confusion with the locale. A "fluent" interface with cascading on an |
| 186 // instance might work better? A list of patterns is also possible. | 186 // instance might work better? A list of patterns is also possible. |
| 187 _locale = Intl.verifiedLocale(locale); | 187 _locale = Intl.verifiedLocale(locale, localeExists); |
| 188 addPattern(newPattern); | 188 addPattern(newPattern); |
| 189 } | 189 } |
| 190 | 190 |
| 191 /** | 191 /** |
| 192 * Return a string representing [date] formatted according to our locale | 192 * Return a string representing [date] formatted according to our locale |
| 193 * and internal format. | 193 * and internal format. |
| 194 */ | 194 */ |
| 195 String format(Date date) { | 195 String format(Date date) { |
| 196 // TODO(efortuna): read optional TimeZone argument (or similar)? | 196 // TODO(efortuna): read optional TimeZone argument (or similar)? |
| 197 var result = new StringBuffer(); | 197 var result = new StringBuffer(); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 } | 501 } |
| 502 | 502 |
| 503 /** | 503 /** |
| 504 * Set the locale. If the locale can't be found, we also look up | 504 * Set the locale. If the locale can't be found, we also look up |
| 505 * based on alternative versions, e.g. if we have no 'en_CA' we will | 505 * based on alternative versions, e.g. if we have no 'en_CA' we will |
| 506 * look for 'en' as a fallback. It will also translate en-ca into en_CA. | 506 * look for 'en' as a fallback. It will also translate en-ca into en_CA. |
| 507 * Null is also considered a valid value for [newLocale], indicating | 507 * Null is also considered a valid value for [newLocale], indicating |
| 508 * to use the default. | 508 * to use the default. |
| 509 */ | 509 */ |
| 510 _setLocale(String newLocale) { | 510 _setLocale(String newLocale) { |
| 511 _locale = Intl.verifiedLocale(newLocale); | 511 _locale = Intl.verifiedLocale(newLocale, localeExists); |
| 512 } | 512 } |
| 513 | 513 |
| 514 /** | 514 /** |
| 515 * Return true if the locale exists, or if it is null. The null case | 515 * Return true if the locale exists, or if it is null. The null case |
| 516 * is interpreted to mean that we use the default locale. | 516 * is interpreted to mean that we use the default locale. |
| 517 */ | 517 */ |
| 518 static bool localeExists(localeName) { | 518 static bool localeExists(localeName) { |
| 519 if (localeName == null) return false; | 519 if (localeName == null) return false; |
| 520 return dateTimeSymbols.containsKey(localeName); | 520 return dateTimeSymbols.containsKey(localeName); |
| 521 } | 521 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 List _reverse(List list) { | 559 List _reverse(List list) { |
| 560 // TODO(alanknight): Use standardized list reverse when implemented. | 560 // TODO(alanknight): Use standardized list reverse when implemented. |
| 561 // See Issue 2804. | 561 // See Issue 2804. |
| 562 var result = new List(); | 562 var result = new List(); |
| 563 for (var i = list.length-1; i >= 0; i--) { | 563 for (var i = list.length-1; i >= 0; i--) { |
| 564 result.addLast(list[i]); | 564 result.addLast(list[i]); |
| 565 } | 565 } |
| 566 return result; | 566 return result; |
| 567 } | 567 } |
| 568 } | 568 } |
| OLD | NEW |