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

Unified Diff: pkg/intl/lib/date_format.dart

Issue 11068011: If no pattern is specified for date formatting, use a default (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 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
« no previous file with comments | « no previous file | pkg/intl/test/date_time_format_test_core.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/intl/lib/date_format.dart
===================================================================
--- pkg/intl/lib/date_format.dart (revision 13269)
+++ pkg/intl/lib/date_format.dart (working copy)
@@ -426,12 +426,22 @@
*/
get _formatFields {
if (_formatFieldsPrivate == null) {
+ if (_pattern == null) _useDefaultPattern();
_formatFieldsPrivate = parsePattern(_pattern);
}
return _formatFieldsPrivate;
}
/**
+ * We are being asked to do formatting without having set any pattern.
+ * Use a default.
+ */
+ _useDefaultPattern() {
+ add_yMMMMd();
+ add_jms();
+ }
+
+ /**
* A series of regular expressions used to parse a format string into its
* component fields.
*/
@@ -454,7 +464,7 @@
* Set our pattern, appending it to any existing patterns. Also adds a single
* space to separate the two.
*/
- _setPattern(String inputPattern, [String separator = ' ']) {
+ _appendPattern(String inputPattern, [String separator = ' ']) {
if (_pattern == null) {
_pattern = inputPattern;
} else {
@@ -473,13 +483,14 @@
// TODO(alanknight): This is an expensive operation. Caching recently used
// formats, or possibly introducing an entire "locale" object that would
// cache patterns for that locale could be a good optimization.
+ // If we have already parsed the format fields, reset them.
+ _formatFieldsPrivate = null;
+ if (inputPattern == null) return this;
if (!_availableSkeletons.containsKey(inputPattern)) {
- _setPattern(inputPattern, separator);
+ _appendPattern(inputPattern, separator);
} else {
- _setPattern(_availableSkeletons[inputPattern], separator);
+ _appendPattern(_availableSkeletons[inputPattern], separator);
}
- // If we have already parsed the format fields, reset them.
- _formatFieldsPrivate = null;
return this;
}
« no previous file with comments | « no previous file | pkg/intl/test/date_time_format_test_core.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698