Index: lib/i18n/date_format.dart |
=================================================================== |
--- lib/i18n/date_format.dart (revision 8135) |
+++ lib/i18n/date_format.dart (working copy) |
@@ -5,11 +5,13 @@ |
* |
* DateFormat is for formatting and parsing dates in a locale-sensitive |
* manner. |
- * It allows the user to use any customized pattern to parse or format |
- * date-time strings under certain locales. Date elements that vary across |
- * locales include month name, weekname, field, order, etc. |
+ * 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 |
+ * vary across locales include month name, weekname, field, order, etc. |
+ * //TODO(efortuna): Customized pattern system -- needs feedback on |
+ * // appropriateness. |
* |
- * This library uses the ICU/JDK date/time pattern specification as described |
+ * This library uses the ICU date/time pattern specification as described |
* below. |
* |
* Time Format Syntax: To specify the time format use a time pattern string. |
@@ -19,7 +21,7 @@ |
* Symbol Meaning Presentation Example |
* ------ ------- ------------ ------- |
* G era designator (Text) AD |
- * y# year (Number) 1996 |
+ * y year (Number) 1996 |
* M month in year (Text & Number) July & 07 |
* d day in month (Number) 10 |
* h hour in am/pm (1~12) (Number) 12 |
@@ -35,11 +37,7 @@ |
* z time zone (Text) Pacific Standard Time |
* Z time zone (RFC 822) (Number) -0800 |
* v time zone (generic) (Text) Pacific Time |
- * ' escape for text (Delimiter) 'Date=' |
- * '' single quote (Literal) 'o''clock' |
* |
- * Items marked with '#' work differently than in Java. |
- * |
* The count of pattern letters determine the format. |
* (Text): 4 or more pattern letters--use full form, |
* less than 4--use short or abbreviated form if one exists. |
@@ -65,12 +63,12 @@ |
* |
* Format Pattern Result |
* -------------- ------- |
- * "yyyy.MM.dd G 'at' HH:mm:ss vvvv"->> 1996.07.10 AD at 15:08:56 Pacific Time |
- * "EEE, MMM d, ''yy" ->> Wed, July 10, '96 |
- * "h:mm a" ->> 12:08 PM |
- * "hh 'o''clock' a, zzzz" ->> 12 o'clock PM, Pacific Daylight Time |
- * "K:mm a, vvv" ->> 0:00 PM, PT |
- * "yyyyy.MMMMM.dd GGG hh:mm aaa" ->> 01996.July.10 AD 12:08 PM |
+ * "yyyy.MM.dd G 'at' HH:mm:ss vvvv"->1996.07.10 AD at 15:08:56 Pacific Time |
+ * "EEE, MMM d, ''yy" ->Wed, July 10, '96 |
+ * "h:mm a" ->12:08 PM |
+ * "hh 'o''clock' a, zzzz" ->12 o'clock PM, Pacific Daylight Time |
+ * "K:mm a, vvv" ->0:00 PM, PT |
+ * "yyyyy.MMMMM.dd GGG hh:mm aaa" ->01996.July.10 AD 12:08 PM |
* |
* When parsing a date string using the abbreviated year pattern ("yy"), |
* DateTimeParse must interpret the abbreviated year relative to some |
@@ -100,49 +98,49 @@ |
* that point, the parse of the run fails. |
*/ |
-#library('DateFormat'); |
+#library('DateTimeFormat'); |
Alan Knight
2012/06/03 17:19:52
I had deliberately called it DateFormat, rather th
|
-class DateFormat { |
+class DateTimeFormat { |
/** Definition of this object formats dates. */ |
- var formatDefinition; |
+ String formatDefinition; |
- /** 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; |
- |
- /** |
- * Named constructors for each of the above values. |
- * These could probably be made shorter if we just set the format to the |
- * constant and the parsing was lazy. |
+ /** |
+ * Date/Time format patterns. Also specifiable by String, but written this way |
+ * so that they can be discoverable via autocomplete. |
*/ |
- 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; |
- |
- DateFormat(this.formatDefinition); |
+ 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 |
+ |
+ DateTimeFormat(this.formatDefinition, [this._locale]) { |
Alan Knight
2012/06/03 17:19:52
Should we allow formatDefinition to also be option
|
+ default_forms = ['Hm', 'Hms', 'M', 'MEd', 'MMM', 'MMMEd', 'MMMMEd', 'MMMMd', |
+ 'MMMd', 'Md', 'd', 'hm', 'ms', 'y', 'yM', 'yMEd', 'yMMM', |
+ 'yMMMEd', 'yMMMM', 'yQ', 'yQQQ']; |
+ // Default to full date and time if it does not match one of our expected |
+ // forms (for now). |
+ if(!default_forms.contains(formatDefinition)) formatDefinition = 'yMMMEd'; |
+ } |
+ |
/** |
* |
*/ |
@@ -154,7 +152,7 @@ |
* Format the given [date] object according to preset pattern and current |
* locale and return a formated string for the given date. |
*/ |
- String format(Date date, [TimeZone timeZone]) { |
+ String format(Date date) { |
// TODO(efortuna): optional TimeZone argument? TimeZone is deprecated... |
return date.toString(); |
} |