Index: lib/i18n/date_format.dart |
=================================================================== |
--- lib/i18n/date_format.dart (revision 8268) |
+++ lib/i18n/date_format.dart (working copy) |
@@ -3,7 +3,7 @@ |
* for details. All rights reserved. Use of this source code is governed by a |
* BSD-style license that can be found in the LICENSE file. |
* |
- * DateTimeFormat is for formatting and parsing dates in a locale-sensitive |
+ * DateFormat is for formatting and parsing dates in a locale-sensitive |
* manner. |
* It allows the user to choose from a set of standard date time formats as well |
* as specify a customized pattern under certain locales. Date elements that |
@@ -105,23 +105,28 @@ |
* that point, the parse of the run fails. |
*/ |
-#library('DateTimeFormat'); |
+#library('DateFormat'); |
-class DateTimeFormat { |
+class DateFormat { |
/** Definition of this object formats dates. */ |
var formatDefinition; |
/** |
* String indicating a language code with which the message is to be |
- * formatted (such as en-US). |
+ * formatted (such as en). |
*/ |
String _locale; |
/** |
* Date/Time format "skeleton" patterns. Also specifiable by String, but |
- * written this way so that they can be discoverable via autocomplete. |
+ * written this way so that they can be discoverable via autocomplete. These |
+ * follow the ICU syntax described at the top of the file. These skeletons can |
+ * be combined and we will attempt to find the best format for each locale |
+ * given the pattern. |
*/ |
+ // Example of how this looks in the US |
+ // locale. |
static final String Hm = 'Hm'; // HH:mm |
static final String Hms = 'Hms'; // HH:mm:ss |
static final String M = 'M'; // L |
@@ -145,38 +150,58 @@ |
static final String yQQQ = 'yQQQ'; // QQQ yyyy |
/** Date/Time format patterns. */ |
- // TODO(alanknight): There's a style question of whether to use fullDate or |
- // FULL_DATE naming conventions. |
- static final int _fullDate = 0; |
- static final int _longDate = 1; |
- static final int _mediumDate = 2; |
- static final int _shortDate = 3; |
- static final int _fullTime = 4; |
- static final int _longTime = 5; |
- static final int _mediumTime = 6; |
- static final int _shortTime = 7; |
- static final int _fullDateTime = 8; |
- static final int _longDateTime = 9; |
- static final int _mediumDateTime = 10; |
- static final int _shortDateTime = 11; |
+ static final String _fullDate = DateFormat.y + DateFormat.MMMMd; |
+ static final String _longDate = DateFormat.yMMMEd; |
+ static final String _mediumDate = DateFormat.y + DateFormat.Md; |
+ static final String _shortDate = DateFormat.Md; |
+ static final String _fullTime = DateFormat.Hms + 'a'; |
+ static final String _longTime = DateFormat.Hms + 'a zzzz'; |
Emily Fortuna
2012/06/04 22:48:48
This will probably be fixed up after we have our m
|
+ static final String _mediumTime = DateFormat.Hms; |
+ static final String _shortTime = DateFormat.Hm; |
+ static final String _fullDateTime = _fullDate + _fullTime; |
+ static final String _longDateTime = _logDate + _longTime; |
+ static final String _mediumDateTime = _mediumDate + _mediumTime; |
+ static final String _shortDateTime = _shortDate + _shortTime; |
/** |
- * Named constructors for each of the above values. |
+ * Named constructors for the above values. |
* These could probably be made shorter if we just set the format to the |
* constant and the parsing was lazy. |
*/ |
- DateTimeFormat.fullDate() : this.formatDefinition = _fullDate; |
- DateTimeFormat.longDate() : this.formatDefinition = _longDate; |
- DateTimeFormat.mediumDate() : this.formatDefinition = _mediumDate; |
- DateTimeFormat.shortDate() : this.formatDefinition = _shortDate; |
- DateTimeFormat.fullTime() : this.formatDefinition = _fullTime; |
- DateTimeFormat.longTime() : this.formatDefinition = _longTime; |
- DateTimeFormat.mediumTime() : this.formatDefinition = _mediumTime; |
- DateTimeFormat.shortTime() : this.formatDefinition = _shortTime; |
- DateTimeFormat.fullDateTime() : this.formatDefinition = _fullDateTime; |
- DateTimeFormat.longDateTime() : this.formatDefinition = _longDateTime; |
- DateTimeFormat.mediumDateTime() : this.formatDefinition = _mediumDateTime; |
- DateTimeFormat.shortDateTime() : this.formatDefinition = _shortDateTime; |
+ DateFormat.Hm() : this.formatDefinition = DateFormat.Hm; |
+ DateFormat.Hms() : this.formatDefinition = DateFormat.Hms; |
+ DateFormat.M() : this.formatDefinition = DateFormat.M; |
+ DateFormat.MEd() : this.formatDefinition = DateFormat.MEd; |
+ DateFormat.MMM() : this.formatDefinition = DateFormat.MMM; |
+ DateFormat.MMMEd() : this.formatDefinition = DateFormat.MMMEd; |
+ DateFormat.MMMMEd() : this.formatDefinition = DateFormat.MMMMEd; |
+ DateFormat.MMMMd() : this.formatDefinition = DateFormat.MMMMd; |
+ DateFormat.MMMd() : this.formatDefinition = DateFormat.MMMd; |
+ DateFormat.Md() : this.formatDefinition = DateFormat.Md; |
+ DateFormat.d() : this.formatDefinition = DateFormat.d; |
+ DateFormat.hm() : this.formatDefinition = DateFormat.hm; |
+ DateFormat.ms() : this.formatDefinition = DateFormat.ms; |
+ DateFormat.y() : this.formatDefinition = DateFormat.y; |
+ DateFormat.yM() : this.formatDefinition = DateFormat.yM; |
+ DateFormat.yMEd() : this.formatDefinition = DateFormat.yMEd; |
+ DateFormat.yMMM() : this.formatDefinition = DateFormat.yMMM; |
+ DateFormat.yMMMEd() : this.formatDefinition = DateFormat.yMMMEd; |
+ DateFormat.yMMMM() : this.formatDefinition = DateFormat.yMMMM; |
+ DateFormat.yQ() : this.formatDefinition = DateFormat.yQ; |
+ DateFormat.yQQQ() : this.formatDefinition = DateFormat.yQQQ; |
+ |
+ DateFormat.fullDate() : this.formatDefinition = _fullDate; |
+ DateFormat.longDate() : this.formatDefinition = _longDate; |
+ DateFormat.mediumDate() : this.formatDefinition = _mediumDate; |
+ DateFormat.shortDate() : this.formatDefinition = _shortDate; |
+ DateFormat.fullTime() : this.formatDefinition = _fullTime; |
+ DateFormat.longTime() : this.formatDefinition = _longTime; |
+ DateFormat.mediumTime() : this.formatDefinition = _mediumTime; |
+ DateFormat.shortTime() : this.formatDefinition = _shortTime; |
+ DateFormat.fullDateTime() : this.formatDefinition = _fullDateTime; |
+ DateFormat.longDateTime() : this.formatDefinition = _longDateTime; |
+ DateFormat.mediumDateTime() : this.formatDefinition = _mediumDateTime; |
+ DateFormat.shortDateTime() : this.formatDefinition = _shortDateTime; |
/** |
* Constructor accepts a [formatDefinition], which can be a String, one of the |
@@ -185,7 +210,7 @@ |
* locale to be used, otherwise, we will attempt to infer it (acceptable if |
* Dart is running on the client, we can infer from the browser). |
*/ |
- DateTimeFormat(this.formatDefinition, [this._locale]); |
+ DateFormat(this.formatDefinition, [this._locale]); |
/** |
* Given user input, attempt to parse the [inputString] into the anticipated |