Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /** | 1 /** |
| 2 * Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 * Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
|
Bob Nystrom
2012/06/06 22:22:48
The copyright block should just be line comments a
Emily Fortuna
2012/06/06 22:51:43
Done.
| |
| 3 * for details. All rights reserved. Use of this source code is governed by a | 3 * for details. All rights reserved. Use of this source code is governed by a |
| 4 * BSD-style license that can be found in the LICENSE file. | 4 * BSD-style license that can be found in the LICENSE file. |
| 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, weekname, field, order, etc. | 10 * vary across locales include month name, weekname, field, order, etc. |
|
Bob Nystrom
2012/06/06 22:22:48
"weekname" -> "week name"
"field, order" -> "field
Emily Fortuna
2012/06/06 22:51:43
These were copied from the Closure docs. :-P Fixed
| |
| 11 * //TODO(efortuna): Customized pattern system -- suggested by i18n needs | 11 * //TODO(efortuna): Customized pattern system -- suggested by i18n needs |
|
Bob Nystrom
2012/06/06 22:22:48
Just so you know, this TODO will get included in t
Emily Fortuna
2012/06/06 22:51:43
Done.
| |
| 12 * // feedback on appropriateness. | 12 * // feedback on appropriateness. |
| 13 * We also allow the user to use any customized pattern to parse or format | 13 * We also allow the user to use any customized pattern to parse or format |
| 14 * date-time strings under certain locales. Date elements that vary across | 14 * date-time strings under certain locales. Date elements that vary across |
| 15 * locales include month name, weekname, field, order, etc. | 15 * locales include month name, weekname, field, order, etc. |
| 16 * | 16 * |
| 17 * This library uses the ICU/JDK date/time pattern specification as described | 17 * This library uses the ICU/JDK date/time pattern specification as described |
| 18 * below. | 18 * below. |
| 19 * | 19 * |
| 20 * Time Format Syntax: To specify the time format use a time pattern string. | 20 * Time Format Syntax: To specify the time format use a time pattern string. |
| 21 * In this pattern, following letters are reserved as pattern letters, which | 21 * In this pattern, following letters are reserved as pattern letters, which |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 39 * K hour in am/pm (0~11) (Number) 0 | 39 * K hour in am/pm (0~11) (Number) 0 |
| 40 * z time zone (Text) Pacific Standard Time | 40 * z time zone (Text) Pacific Standard Time |
| 41 * Z time zone (RFC 822) (Number) -0800 | 41 * Z time zone (RFC 822) (Number) -0800 |
| 42 * v time zone (generic) (Text) Pacific Time | 42 * v time zone (generic) (Text) Pacific Time |
| 43 * ' escape for text (Delimiter) 'Date=' | 43 * ' escape for text (Delimiter) 'Date=' |
| 44 * '' single quote (Literal) 'o''clock' | 44 * '' single quote (Literal) 'o''clock' |
| 45 * | 45 * |
| 46 * Items marked with '#' work differently than in Java. | 46 * Items marked with '#' work differently than in Java. |
| 47 * | 47 * |
| 48 * The count of pattern letters determine the format. | 48 * The count of pattern letters determine the format. |
| 49 * (Text): 4 or more pattern letters--use full form, | 49 * (Text): 4 or more pattern letters--use full form, |
|
Bob Nystrom
2012/06/06 22:22:48
You could use a markdown bullet list here, with em
Emily Fortuna
2012/06/06 22:51:43
Done.
| |
| 50 * less than 4--use short or abbreviated form if one exists. | 50 * less than 4--use short or abbreviated form if one exists. |
| 51 * In parsing, we will always try long format, then short. | 51 * In parsing, we will always try long format, then short. |
| 52 * (e.g., "EEEE" produces "Monday", "EEE" produces "Mon") | 52 * (e.g., "EEEE" produces "Monday", "EEE" produces "Mon") |
| 53 * | 53 * |
| 54 * (Number): the minimum number of digits. Shorter numbers are zero-padded to | 54 * (Number): the minimum number of digits. Shorter numbers are zero-padded to |
| 55 * this amount (e.g. if "m" produces "6", "mm" produces "06"). Year is handled | 55 * this amount (e.g. if "m" produces "6", "mm" produces "06"). Year is handled |
| 56 * specially; that is, if the count of 'y' is 2, the Year will be truncated to | 56 * specially; that is, if the count of 'y' is 2, the Year will be truncated to |
| 57 * 2 digits. (e.g., if "yyyy" produces "1997", "yy" produces "97".) Unlike other | 57 * 2 digits. (e.g., if "yyyy" produces "1997", "yy" produces "97".) Unlike other |
| 58 * fields, fractional seconds are padded on the right with zero. | 58 * fields, fractional seconds are padded on the right with zero. |
| 59 * | 59 * |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 * the run, then the leftmost field is shortened by one character, and the | 102 * the run, then the leftmost field is shortened by one character, and the |
| 103 * entire run is parsed again. This is repeated until either the parse succeeds | 103 * entire run is parsed again. This is repeated until either the parse succeeds |
| 104 * or the leftmost field is one character in length. If the parse still fails at | 104 * or the leftmost field is one character in length. If the parse still fails at |
| 105 * that point, the parse of the run fails. | 105 * that point, the parse of the run fails. |
| 106 */ | 106 */ |
| 107 | 107 |
| 108 #library('DateFormat'); | 108 #library('DateFormat'); |
| 109 | 109 |
| 110 class DateFormat { | 110 class DateFormat { |
| 111 | 111 |
| 112 /** Definition of this object formats dates. */ | 112 /** Definition of this object formats dates. */ |
|
Bob Nystrom
2012/06/06 22:22:48
"formats" -> "format's"?
Emily Fortuna
2012/06/06 22:51:43
(added "how") done.
| |
| 113 var formatDefinition; | 113 var formatDefinition; |
|
Bob Nystrom
2012/06/06 22:22:48
Can this be typed? Should it be public and mutable
Emily Fortuna
2012/06/06 22:51:43
Done.
| |
| 114 | 114 |
| 115 /** | 115 /** |
| 116 * String indicating the locale code with which the message is to be | 116 * String indicating the locale code with which the message is to be |
|
Bob Nystrom
2012/06/06 22:22:48
Remove "String indicating".
Emily Fortuna
2012/06/06 22:51:43
Done.
Emily Fortuna
2012/06/06 22:51:43
Done.
| |
| 117 * formatted (such as en-CA). | 117 * formatted (such as en-CA). |
| 118 */ | 118 */ |
| 119 String _locale; | 119 String _locale; |
| 120 | 120 |
| 121 /** | 121 /** |
| 122 * Date/Time format "skeleton" patterns. Also specifiable by String, but | 122 * Date/Time format "skeleton" patterns. Also specifiable by String, but |
| 123 * written this way so that they can be discoverable via autocomplete. These | 123 * written this way so that they can be discoverable via autocomplete. These |
|
Bob Nystrom
2012/06/06 22:22:48
Yay autocomplete!
| |
| 124 * follow the ICU syntax described at the top of the file. These skeletons can | 124 * follow the ICU syntax described at the top of the file. These skeletons can |
| 125 * be combined and we will attempt to find the best format for each locale | 125 * be combined and we will attempt to find the best format for each locale |
| 126 * given the pattern. | 126 * given the pattern. |
| 127 * // TODO(efortuna): Hear back from i18n about Time Zones and the "core set" | 127 * // TODO(efortuna): Hear back from i18n about Time Zones and the "core set" |
| 128 * // of skeleton patterns. | 128 * // of skeleton patterns. |
| 129 */ | 129 */ |
| 130 // Example of how this looks in the US | 130 // Example of how this looks in the US |
| 131 // locale. | 131 // locale. |
| 132 static final String Hm = 'Hm'; // HH:mm | 132 static final String Hm = 'Hm'; // HH:mm |
| 133 static final String Hms = 'Hms'; // HH:mm:ss | 133 static final String Hms = 'Hms'; // HH:mm:ss |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 DateFormat.mediumDateTime([this._locale]) : formatDefinition = mediumDateTime; | 206 DateFormat.mediumDateTime([this._locale]) : formatDefinition = mediumDateTime; |
| 207 DateFormat.shortDateTime([this._locale]) : formatDefinition = shortDateTime; | 207 DateFormat.shortDateTime([this._locale]) : formatDefinition = shortDateTime; |
| 208 | 208 |
| 209 /** | 209 /** |
| 210 * Constructor accepts a [formatDefinition], which can be a String, one of the | 210 * Constructor accepts a [formatDefinition], which can be a String, one of the |
| 211 * predefined static forms, or a custom date format using the syntax described | 211 * predefined static forms, or a custom date format using the syntax described |
| 212 * above. An optional [_locale] can be provided for specifics of the language | 212 * above. An optional [_locale] can be provided for specifics of the language |
| 213 * locale to be used, otherwise, we will attempt to infer it (acceptable if | 213 * locale to be used, otherwise, we will attempt to infer it (acceptable if |
| 214 * Dart is running on the client, we can infer from the browser). | 214 * Dart is running on the client, we can infer from the browser). |
| 215 */ | 215 */ |
| 216 DateFormat([this.formatDefinition = fullDate, this._locale]); | 216 DateFormat([this.formatDefinition = fullDate, this._locale]); |
|
Bob Nystrom
2012/06/06 22:22:48
I think we try not to use private names as named p
Emily Fortuna
2012/06/06 22:51:43
Done.
| |
| 217 | 217 |
| 218 /** | 218 /** |
| 219 * Given user input, attempt to parse the [inputString] into the anticipated | 219 * Given user input, attempt to parse the [inputString] into the anticipated |
| 220 * format. | 220 * format. |
| 221 */ | 221 */ |
| 222 String parse(String inputString) { | 222 String parse(String inputString) { |
| 223 return inputString; | 223 return inputString; |
| 224 } | 224 } |
| 225 | 225 |
| 226 /** | 226 /** |
| 227 * Format the given [date] object according to preset pattern and current | 227 * Format the given [date] object according to preset pattern and current |
| 228 * locale and return a formated string for the given date. | 228 * locale and return a formated string for the given date. |
| 229 */ | 229 */ |
| 230 String format(Date date, [TimeZone timeZone]) { | 230 String format(Date date, [TimeZone timeZone]) { |
| 231 // TODO(efortuna): optional TimeZone argument? TimeZone is deprecated... | 231 // TODO(efortuna): optional TimeZone argument? TimeZone is deprecated... |
| 232 return date.toString(); | 232 return date.toString(); |
| 233 } | 233 } |
| 234 | 234 |
| 235 /** | 235 /** |
| 236 * Returns a date string indicating how long ago (3 hours, 2 minutes) | 236 * Returns a date string indicating how long ago (3 hours, 2 minutes) |
| 237 * something has happened or how long in the future something will happen | 237 * something has happened or how long in the future something will happen |
| 238 * given a [reference] Date relative to the current time. | 238 * given a [reference] Date relative to the current time. |
| 239 */ | 239 */ |
| 240 String formatDuration(Date reference) { | 240 String formatDuration(Date reference) { |
| 241 return ''; | 241 return ''; |
| 242 } | 242 } |
| 243 | 243 |
| 244 /** | 244 /** |
| 245 * Formats a String indicating how long ago (negative [duration]) or how far | 245 * Formats a String indicating how long ago (negative [duration]) or how far |
|
Bob Nystrom
2012/06/06 22:22:48
I would either put "String" in [] or make it lower
Emily Fortuna
2012/06/06 22:51:43
Done.
| |
| 246 * in the future (positive [duration]) some time is with respect to a | 246 * in the future (positive [duration]) some time is with respect to a |
| 247 * reference [date]. The [duration] is expressed in miliseconds. | 247 * reference [date]. |
| 248 */ | 248 */ |
| 249 String formatDurationFrom(num duration, Date date) { | 249 String formatDurationFrom(Duration duration, Date date) { |
| 250 return ''; | 250 return ''; |
| 251 } | 251 } |
| 252 } | 252 } |
| OLD | NEW |