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,78 +105,108 @@ |
* 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). |
Alan Knight
2012/06/04 23:59:00
I think this is still not right. It's the locale,
|
*/ |
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. |
+ * // TODO(efortuna): Hear back from i18n about Time Zones and the "core set" |
+ * // of skeleton patterns. |
*/ |
- static final String Hm = 'Hm'; // HH:mm |
- static final String Hms = 'Hms'; // HH:mm:ss |
- static final String M = 'M'; // L |
- static final String MEd = 'MEd'; // E, M/d |
- static final String MMM = 'MMM'; // LLL |
- static final String MMMEd = 'MMMEd'; // E, MMM d |
- static final String MMMMEd = 'MMMMEd'; // E, MMMM d |
- static final String MMMMd = 'MMMMd'; // MMMM d |
- static final String MMMd = 'MMMd'; // MMM d |
- static final String Md = 'Md'; // M/d |
- static final String d = 'd'; // d |
- static final String hm = 'hm'; // h:mm a |
- static final String ms = 'ms'; // mm:ss |
- static final String y = 'y'; // yyyy |
- static final String yM = 'yM'; // M/yyyy |
- static final String yMEd = 'yMEd'; // EEE, M/d/yyyy |
- static final String yMMM = 'yMMM'; // MMM yyyy |
- static final String yMMMEd = 'yMMMEd'; // EEE, MM d, yyyy |
- static final String yMMMM = 'yMMMM'; // MMMM yyyy |
- static final String yQ = 'yQ'; // Q yyyy |
- static final String yQQQ = 'yQQQ'; // QQQ yyyy |
+ // 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 |
+ static final String _MEd = 'MEd'; // E, M/d |
+ static final String _MMM = 'MMM'; // LLL |
+ static final String _MMMEd = 'MMMEd'; // E, MMM d |
+ static final String _MMMMEd = 'MMMMEd'; // E, MMMM d |
+ static final String _MMMMd = 'MMMMd'; // MMMM d |
+ static final String _MMMd = 'MMMd'; // MMM d |
+ static final String _Md = 'Md'; // M/d |
+ static final String _d = 'd'; // d |
+ static final String _hm = 'hm'; // h:mm a |
+ static final String _ms = 'ms'; // mm:ss |
+ static final String _y = 'y'; // yyyy |
+ static final String _yM = 'yM'; // M/yyyy |
+ static final String _yMEd = 'yMEd'; // EEE, M/d/yyyy |
+ static final String _yMMM = 'yMMM'; // MMM yyyy |
+ static final String _yMMMEd = 'yMMMEd'; // EEE, MM d, yyyy |
+ static final String _yMMMM = 'yMMMM'; // MMMM yyyy |
+ static final String _yQ = 'yQ'; // Q yyyy |
+ 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; |
+ // TODO(efortuna): This are just guesses of what a full date, long date is. |
+ // Do the proper homework on ICU to find the proper set "Hms"/"yMMd" |
+ // applicable to each case. |
+ static final String _fullDate = DateFormat._y + DateFormat._MMMMd; |
Alan Knight
2012/06/04 23:59:00
I thought we don't have String + any more.
Emily Fortuna
2012/06/05 00:21:50
Yup. old habits die hard. Fixed.
|
+ static final String _longDate = DateFormat._yMMMEd; |
+ static final String _mediumDate = DateFormat._y + DateFormat._Md; |
Alan Knight
2012/06/04 23:59:00
Couldn't we just write these as e.g. _y + _Md, sin
Emily Fortuna
2012/06/05 00:21:50
Duh! fixed!
|
+ static final String _shortDate = DateFormat._Md; |
+ static final String _fullTime = DateFormat._Hms + 'a'; |
+ static final String _longTime = DateFormat._Hms + 'a zzzz'; |
+ 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. |
Alan Knight
2012/06/04 23:59:00
I think the last two lines of this comment are obs
Emily Fortuna
2012/06/05 00:21:50
Done.
|
*/ |
- 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 +215,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 |