Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(944)

Side by Side Diff: lib/i18n/date_format.dart

Issue 10700013: revert 9192,9194 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/i18n/bidi_utils.dart ('k') | lib/i18n/intl.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 * 49 * **Text**:
50 * **Text**:
51 *
52 * * 4 or more pattern letters--use full form, 50 * * 4 or more pattern letters--use full form,
53 * * less than 4--use short or abbreviated form if one exists. 51 * * less than 4--use short or abbreviated form if one exists.
54 * In parsing, we will always try long format, then short. 52 * In parsing, we will always try long format, then short.
55 * (e.g., "EEEE" produces "Monday", "EEE" produces "Mon") 53 * (e.g., "EEEE" produces "Monday", "EEE" produces "Mon")
56 * 54 *
57 * **Number**: the minimum number of digits. Shorter numbers are zero-padded to 55 * **Number**: the minimum number of digits. Shorter numbers are zero-padded to
58 * this amount (e.g. if "m" produces "6", "mm" produces "06"). Year is handled 56 * this amount (e.g. if "m" produces "6", "mm" produces "06"). Year is handled
59 * specially; that is, if the count of 'y' is 2, the Year will be truncated to 57 * specially; that is, if the count of 'y' is 2, the Year will be truncated to
60 * 2 digits. (e.g., if "yyyy" produces "1997", "yy" produces "97".) Unlike other 58 * 2 digits. (e.g., if "yyyy" produces "1997", "yy" produces "97".) Unlike other
61 * fields, fractional seconds are padded on the right with zero. 59 * fields, fractional seconds are padded on the right with zero.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 * runs are parsed specially. For example, the format "HHmmss" parses the input 99 * runs are parsed specially. For example, the format "HHmmss" parses the input
102 * text "123456" to 12:34:56, parses the input text "12345" to 1:23:45, and 100 * text "123456" to 12:34:56, parses the input text "12345" to 1:23:45, and
103 * fails to parse "1234". In other words, the leftmost field of the run is 101 * fails to parse "1234". In other words, the leftmost field of the run is
104 * flexible, while the others keep a fixed width. If the parse fails anywhere in 102 * flexible, while the others keep a fixed width. If the parse fails anywhere in
105 * the run, then the leftmost field is shortened by one character, and the 103 * the run, then the leftmost field is shortened by one character, and the
106 * entire run is parsed again. This is repeated until either the parse succeeds 104 * entire run is parsed again. This is repeated until either the parse succeeds
107 * or the leftmost field is one character in length. If the parse still fails at 105 * or the leftmost field is one character in length. If the parse still fails at
108 * that point, the parse of the run fails. 106 * that point, the parse of the run fails.
109 */ 107 */
110 108
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. When this is complete, also properly comment these 129 // of skeleton patterns.
130 // so the documentation is available on api_docs.
131 // Example of how this looks in the US 130 // Example of how this looks in the US
132 // locale. 131 // locale.
133 static final String Hm = 'Hm'; // HH:mm 132 static final String Hm = 'Hm'; // HH:mm
134 static final String Hms = 'Hms'; // HH:mm:ss 133 static final String Hms = 'Hms'; // HH:mm:ss
135 static final String M = 'M'; // L 134 static final String M = 'M'; // L
136 static final String MEd = 'MEd'; // E, M/d 135 static final String MEd = 'MEd'; // E, M/d
137 static final String MMM = 'MMM'; // LLL 136 static final String MMM = 'MMM'; // LLL
138 static final String MMMEd = 'MMMEd'; // E, MMM d 137 static final String MMMEd = 'MMMEd'; // E, MMM d
139 static final String MMMMEd = 'MMMMEd'; // E, MMMM d 138 static final String MMMMEd = 'MMMMEd'; // E, MMMM d
140 static final String MMMMd = 'MMMMd'; // MMMM d 139 static final String MMMMd = 'MMMMd'; // MMMM d
(...skipping 24 matching lines...) Expand all
165 static final String mediumTime = Hms; 164 static final String mediumTime = Hms;
166 static final String shortTime = Hm; 165 static final String shortTime = Hm;
167 static final String fullDateTime = '$fullDate$fullTime'; 166 static final String fullDateTime = '$fullDate$fullTime';
168 static final String longDateTime = '$longDate$longTime'; 167 static final String longDateTime = '$longDate$longTime';
169 static final String mediumDateTime = '$mediumDate$mediumTime'; 168 static final String mediumDateTime = '$mediumDate$mediumTime';
170 static final String shortDateTime = '$shortDate$shortTime'; 169 static final String shortDateTime = '$shortDate$shortTime';
171 170
172 /** 171 /**
173 * Constructors for dates/times that use a default format. 172 * Constructors for dates/times that use a default format.
174 */ 173 */
175 DateFormat.Hm([locale=this._locale]) : _formatDefinition = Hm; 174 DateFormat.Hm([this._locale]) : _formatDefinition = Hm;
176 DateFormat.Hms([locale=this._locale]) : _formatDefinition = Hms; 175 DateFormat.Hms([this._locale]) : _formatDefinition = Hms;
177 DateFormat.M([locale=this._locale]) : _formatDefinition = M; 176 DateFormat.M([this._locale]) : _formatDefinition = M;
178 DateFormat.MEd([locale=this._locale]) : _formatDefinition = MEd; 177 DateFormat.MEd([this._locale]) : _formatDefinition = MEd;
179 DateFormat.MMM([locale=this._locale]) : _formatDefinition = MMM; 178 DateFormat.MMM([this._locale]) : _formatDefinition = MMM;
180 DateFormat.MMMEd([locale=this._locale]) : _formatDefinition = MMMEd; 179 DateFormat.MMMEd([this._locale]) : _formatDefinition = MMMEd;
181 DateFormat.MMMMEd([locale=this._locale]) : _formatDefinition = MMMMEd; 180 DateFormat.MMMMEd([this._locale]) : _formatDefinition = MMMMEd;
182 DateFormat.MMMMd([locale=this._locale]) : _formatDefinition = MMMMd; 181 DateFormat.MMMMd([this._locale]) : _formatDefinition = MMMMd;
183 DateFormat.MMMd([locale=this._locale]) : _formatDefinition = MMMd; 182 DateFormat.MMMd([this._locale]) : _formatDefinition = MMMd;
184 DateFormat.Md([locale=this._locale]) : _formatDefinition = Md; 183 DateFormat.Md([this._locale]) : _formatDefinition = Md;
185 DateFormat.d([locale=this._locale]) : _formatDefinition = d; 184 DateFormat.d([this._locale]) : _formatDefinition = d;
186 DateFormat.hm([locale=this._locale]) : _formatDefinition = hm; 185 DateFormat.hm([this._locale]) : _formatDefinition = hm;
187 DateFormat.ms([locale=this._locale]) : _formatDefinition = ms; 186 DateFormat.ms([this._locale]) : _formatDefinition = ms;
188 DateFormat.y([locale=this._locale]) : _formatDefinition = y; 187 DateFormat.y([this._locale]) : _formatDefinition = y;
189 DateFormat.yM([locale=this._locale]) : _formatDefinition = yM; 188 DateFormat.yM([this._locale]) : _formatDefinition = yM;
190 DateFormat.yMEd([locale=this._locale]) : _formatDefinition = yMEd; 189 DateFormat.yMEd([this._locale]) : _formatDefinition = yMEd;
191 DateFormat.yMMM([locale=this._locale]) : _formatDefinition = yMMM; 190 DateFormat.yMMM([this._locale]) : _formatDefinition = yMMM;
192 DateFormat.yMMMEd([locale=this._locale]) : _formatDefinition = yMMMEd; 191 DateFormat.yMMMEd([this._locale]) : _formatDefinition = yMMMEd;
193 DateFormat.yMMMM([locale=this._locale]) : _formatDefinition = yMMMM; 192 DateFormat.yMMMM([this._locale]) : _formatDefinition = yMMMM;
194 DateFormat.yQ([locale=this._locale]) : _formatDefinition = yQ; 193 DateFormat.yQ([this._locale]) : _formatDefinition = yQ;
195 DateFormat.yQQQ([locale=this._locale]) : _formatDefinition = yQQQ; 194 DateFormat.yQQQ([this._locale]) : _formatDefinition = yQQQ;
196 195
197 DateFormat.fullDate([locale=this._locale]) : _formatDefinition = fullDate; 196 DateFormat.fullDate([this._locale]) : _formatDefinition = fullDate;
198 DateFormat.longDate([locale=this._locale]) : _formatDefinition = longDate; 197 DateFormat.longDate([this._locale]) : _formatDefinition = longDate;
199 DateFormat.mediumDate([locale=this._locale]) : _formatDefinition = mediumDate; 198 DateFormat.mediumDate([this._locale]) : _formatDefinition = mediumDate;
200 DateFormat.shortDate([locale=this._locale]) : _formatDefinition = shortDate; 199 DateFormat.shortDate([this._locale]) : _formatDefinition = shortDate;
201 DateFormat.fullTime([locale=this._locale]) : _formatDefinition = fullTime; 200 DateFormat.fullTime([this._locale]) : _formatDefinition = fullTime;
202 DateFormat.longTime([locale=this._locale]) : _formatDefinition = longTime; 201 DateFormat.longTime([this._locale]) : _formatDefinition = longTime;
203 DateFormat.mediumTime([locale=this._locale]) : _formatDefinition = mediumTime; 202 DateFormat.mediumTime([this._locale]) : _formatDefinition = mediumTime;
204 DateFormat.shortTime([locale=this._locale]) : _formatDefinition = shortTime; 203 DateFormat.shortTime([this._locale]) : _formatDefinition = shortTime;
205 DateFormat.fullDateTime([locale=this._locale]) : 204 DateFormat.fullDateTime([this._locale]) : _formatDefinition = fullDateTime;
206 _formatDefinition = fullDateTime; 205 DateFormat.longDateTime([this._locale]) : _formatDefinition = longDateTime;
207 DateFormat.longDateTime([locale=this._locale]) : 206 DateFormat.mediumDateTime([this._locale]) : _formatDefinition = mediumDateTime ;
208 _formatDefinition = longDateTime; 207 DateFormat.shortDateTime([this._locale]) : _formatDefinition = shortDateTime;
209 DateFormat.mediumDateTime([locale=this._locale]) :
210 _formatDefinition = mediumDateTime;
211 DateFormat.shortDateTime([locale=this._locale]) :
212 _formatDefinition = shortDateTime;
213 208
214 /** 209 /**
215 * 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
216 * 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
217 * 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
218 * 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
219 * 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).
220 */ 215 */
221 DateFormat([formatDefinition = fullDate, locale]) { 216 DateFormat([formatDefinition = fullDate, locale]) {
222 this._formatDefinition = formatDefinition; 217 this._formatDefinition = formatDefinition;
(...skipping 28 matching lines...) Expand all
251 246
252 /** 247 /**
253 * Formats a string indicating how long ago (negative [duration]) or how far 248 * Formats a string indicating how long ago (negative [duration]) or how far
254 * in the future (positive [duration]) some time is with respect to a 249 * in the future (positive [duration]) some time is with respect to a
255 * reference [date]. 250 * reference [date].
256 */ 251 */
257 String formatDurationFrom(Duration duration, Date date) { 252 String formatDurationFrom(Duration duration, Date date) {
258 return ''; 253 return '';
259 } 254 }
260 } 255 }
OLDNEW
« no previous file with comments | « lib/i18n/bidi_utils.dart ('k') | lib/i18n/intl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698