| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 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, week name, field order, etc. | 10 * vary across locales include month name, week name, field order, etc. |
| (...skipping 28 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**: | 49 * |
| 50 * **Text**: |
| 51 * |
| 50 * * 4 or more pattern letters--use full form, | 52 * * 4 or more pattern letters--use full form, |
| 51 * * less than 4--use short or abbreviated form if one exists. | 53 * * less than 4--use short or abbreviated form if one exists. |
| 52 * In parsing, we will always try long format, then short. | 54 * In parsing, we will always try long format, then short. |
| 53 * (e.g., "EEEE" produces "Monday", "EEE" produces "Mon") | 55 * (e.g., "EEEE" produces "Monday", "EEE" produces "Mon") |
| 54 * | 56 * |
| 55 * **Number**: the minimum number of digits. Shorter numbers are zero-padded to | 57 * **Number**: the minimum number of digits. Shorter numbers are zero-padded to |
| 56 * this amount (e.g. if "m" produces "6", "mm" produces "06"). Year is handled | 58 * this amount (e.g. if "m" produces "6", "mm" produces "06"). Year is handled |
| 57 * specially; that is, if the count of 'y' is 2, the Year will be truncated to | 59 * specially; that is, if the count of 'y' is 2, the Year will be truncated to |
| 58 * 2 digits. (e.g., if "yyyy" produces "1997", "yy" produces "97".) Unlike other | 60 * 2 digits. (e.g., if "yyyy" produces "1997", "yy" produces "97".) Unlike other |
| 59 * fields, fractional seconds are padded on the right with zero. | 61 * fields, fractional seconds are padded on the right with zero. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 * runs are parsed specially. For example, the format "HHmmss" parses the input | 101 * runs are parsed specially. For example, the format "HHmmss" parses the input |
| 100 * text "123456" to 12:34:56, parses the input text "12345" to 1:23:45, and | 102 * text "123456" to 12:34:56, parses the input text "12345" to 1:23:45, and |
| 101 * fails to parse "1234". In other words, the leftmost field of the run is | 103 * fails to parse "1234". In other words, the leftmost field of the run is |
| 102 * flexible, while the others keep a fixed width. If the parse fails anywhere in | 104 * flexible, while the others keep a fixed width. If the parse fails anywhere in |
| 103 * the run, then the leftmost field is shortened by one character, and the | 105 * the run, then the leftmost field is shortened by one character, and the |
| 104 * entire run is parsed again. This is repeated until either the parse succeeds | 106 * entire run is parsed again. This is repeated until either the parse succeeds |
| 105 * or the leftmost field is one character in length. If the parse still fails at | 107 * or the leftmost field is one character in length. If the parse still fails at |
| 106 * that point, the parse of the run fails. | 108 * that point, the parse of the run fails. |
| 107 */ | 109 */ |
| 108 | 110 |
| 109 #library('date_format'); | |
| 110 | |
| 111 class DateFormat { | 111 class DateFormat { |
| 112 | 112 |
| 113 /** Definition of how this object formats dates. */ | 113 /** Definition of how this object formats dates. */ |
| 114 String _formatDefinition; | 114 String _formatDefinition; |
| 115 | 115 |
| 116 /** | 116 /** |
| 117 * The locale code with which the message is to be formatted (such as en-CA). | 117 * The locale code with which the message is to be 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 |
| 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 */ | 127 */ |
| 128 // TODO(efortuna): Hear back from i18n about Time Zones and the "core set" | 128 // TODO(efortuna): Hear back from i18n about Time Zones and the "core set" |
| 129 // of skeleton patterns. | 129 // of skeleton patterns. When this is complete, also properly comment these |
| 130 // so the documentation is available on api_docs. |
| 130 // Example of how this looks in the US | 131 // Example of how this looks in the US |
| 131 // locale. | 132 // locale. |
| 132 static final String Hm = 'Hm'; // HH:mm | 133 static final String Hm = 'Hm'; // HH:mm |
| 133 static final String Hms = 'Hms'; // HH:mm:ss | 134 static final String Hms = 'Hms'; // HH:mm:ss |
| 134 static final String M = 'M'; // L | 135 static final String M = 'M'; // L |
| 135 static final String MEd = 'MEd'; // E, M/d | 136 static final String MEd = 'MEd'; // E, M/d |
| 136 static final String MMM = 'MMM'; // LLL | 137 static final String MMM = 'MMM'; // LLL |
| 137 static final String MMMEd = 'MMMEd'; // E, MMM d | 138 static final String MMMEd = 'MMMEd'; // E, MMM d |
| 138 static final String MMMMEd = 'MMMMEd'; // E, MMMM d | 139 static final String MMMMEd = 'MMMMEd'; // E, MMMM d |
| 139 static final String MMMMd = 'MMMMd'; // MMMM d | 140 static final String MMMMd = 'MMMMd'; // MMMM d |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 247 |
| 247 /** | 248 /** |
| 248 * Formats a string indicating how long ago (negative [duration]) or how far | 249 * Formats a string indicating how long ago (negative [duration]) or how far |
| 249 * in the future (positive [duration]) some time is with respect to a | 250 * in the future (positive [duration]) some time is with respect to a |
| 250 * reference [date]. | 251 * reference [date]. |
| 251 */ | 252 */ |
| 252 String formatDurationFrom(Duration duration, Date date) { | 253 String formatDurationFrom(Duration duration, Date date) { |
| 253 return ''; | 254 return ''; |
| 254 } | 255 } |
| 255 } | 256 } |
| OLD | NEW |