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 part of intl; | 5 part of intl; |
6 | 6 |
7 // TODO(efortuna): Customized pattern system -- suggested by i18n needs | 7 // TODO(efortuna): Customized pattern system -- suggested by i18n needs |
8 // feedback on appropriateness. | 8 // feedback on appropriateness. |
9 /** | 9 /** |
10 * DateFormat is for formatting and parsing dates in a locale-sensitive | 10 * DateFormat is for formatting and parsing dates in a locale-sensitive |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 * "EEE, MMM d, ''yy" Wed, July 10, '96 | 165 * "EEE, MMM d, ''yy" Wed, July 10, '96 |
166 * "h:mm a" 12:08 PM | 166 * "h:mm a" 12:08 PM |
167 * "hh 'o''clock' a, zzzz" 12 o'clock PM, Pacific Daylight Time | 167 * "hh 'o''clock' a, zzzz" 12 o'clock PM, Pacific Daylight Time |
168 * "K:mm a, vvv" 0:00 PM, PT | 168 * "K:mm a, vvv" 0:00 PM, PT |
169 * "yyyyy.MMMMM.dd GGG hh:mm aaa" 01996.July.10 AD 12:08 PM | 169 * "yyyyy.MMMMM.dd GGG hh:mm aaa" 01996.July.10 AD 12:08 PM |
170 * | 170 * |
171 * When parsing a date string using the abbreviated year pattern ("yy"), | 171 * When parsing a date string using the abbreviated year pattern ("yy"), |
172 * DateFormat must interpret the abbreviated year relative to some | 172 * DateFormat must interpret the abbreviated year relative to some |
173 * century. It does this by adjusting dates to be within 80 years before and 20 | 173 * century. It does this by adjusting dates to be within 80 years before and 20 |
174 * years after the time the parse function is called. For example, using a | 174 * years after the time the parse function is called. For example, using a |
175 * pattern of "MM/dd/yy" and a DateTimeParse instance created on Jan 1, 1997, | 175 * pattern of "MM/dd/yy" and a DateParse instance created on Jan 1, 1997, |
176 * the string "01/11/12" would be interpreted as Jan 11, 2012 while the string | 176 * the string "01/11/12" would be interpreted as Jan 11, 2012 while the string |
177 * "05/04/64" would be interpreted as May 4, 1964. During parsing, only | 177 * "05/04/64" would be interpreted as May 4, 1964. During parsing, only |
178 * strings consisting of exactly two digits, as defined by {@link | 178 * strings consisting of exactly two digits, as defined by {@link |
179 * java.lang.Character#isDigit(char)}, will be parsed into the default | 179 * java.lang.Character#isDigit(char)}, will be parsed into the default |
180 * century. Any other numeric string, such as a one digit string, a three or | 180 * century. Any other numeric string, such as a one digit string, a three or |
181 * more digit string will be interpreted as its face value. | 181 * more digit string will be interpreted as its face value. |
182 * | 182 * |
183 * If the year pattern does not have exactly two 'y' characters, the year is | 183 * If the year pattern does not have exactly two 'y' characters, the year is |
184 * interpreted literally, regardless of the number of digits. So using the | 184 * interpreted literally, regardless of the number of digits. So using the |
185 * pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D. | 185 * pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D. |
(...skipping 29 matching lines...) Expand all Loading... |
215 // confusion with the locale. A "fluent" interface with cascading on an | 215 // confusion with the locale. A "fluent" interface with cascading on an |
216 // instance might work better? A list of patterns is also possible. | 216 // instance might work better? A list of patterns is also possible. |
217 _locale = Intl.verifiedLocale(locale, localeExists); | 217 _locale = Intl.verifiedLocale(locale, localeExists); |
218 addPattern(newPattern); | 218 addPattern(newPattern); |
219 } | 219 } |
220 | 220 |
221 /** | 221 /** |
222 * Return a string representing [date] formatted according to our locale | 222 * Return a string representing [date] formatted according to our locale |
223 * and internal format. | 223 * and internal format. |
224 */ | 224 */ |
225 String format(Date date) { | 225 String format(DateTime date) { |
226 // TODO(efortuna): read optional TimeZone argument (or similar)? | 226 // TODO(efortuna): read optional TimeZone argument (or similar)? |
227 var result = new StringBuffer(); | 227 var result = new StringBuffer(); |
228 _formatFields.forEach((field) => result.add(field.format(date))); | 228 _formatFields.forEach((field) => result.add(field.format(date))); |
229 return result.toString(); | 229 return result.toString(); |
230 } | 230 } |
231 | 231 |
232 /** | 232 /** |
233 * Returns a date string indicating how long ago (3 hours, 2 minutes) | 233 * Returns a date string indicating how long ago (3 hours, 2 minutes) |
234 * something has happened or how long in the future something will happen | 234 * something has happened or how long in the future something will happen |
235 * given a [reference] Date relative to the current time. | 235 * given a [reference] DateTime relative to the current time. |
236 */ | 236 */ |
237 String formatDuration(Date reference) { | 237 String formatDuration(DateTime reference) { |
238 return ''; | 238 return ''; |
239 } | 239 } |
240 | 240 |
241 /** | 241 /** |
242 * Formats a string indicating how long ago (negative [duration]) or how far | 242 * Formats a string indicating how long ago (negative [duration]) or how far |
243 * in the future (positive [duration]) some time is with respect to a | 243 * in the future (positive [duration]) some time is with respect to a |
244 * reference [date]. | 244 * reference [date]. |
245 */ | 245 */ |
246 String formatDurationFrom(Duration duration, Date date) { | 246 String formatDurationFrom(Duration duration, DateTime date) { |
247 return ''; | 247 return ''; |
248 } | 248 } |
249 | 249 |
250 /** | 250 /** |
251 * Given user input, attempt to parse the [inputString] into the anticipated | 251 * Given user input, attempt to parse the [inputString] into the anticipated |
252 * format, treating it as being in the local timezone. | 252 * format, treating it as being in the local timezone. |
253 */ | 253 */ |
254 Date parse(String inputString, [utc = false]) { | 254 DateTime parse(String inputString, [utc = false]) { |
255 // TODO(alanknight): The Closure code refers to special parsing of numeric | 255 // TODO(alanknight): The Closure code refers to special parsing of numeric |
256 // values with no delimiters, which we currently don't do. Should we? | 256 // values with no delimiters, which we currently don't do. Should we? |
257 var dateFields = new _DateBuilder(); | 257 var dateFields = new _DateBuilder(); |
258 if (utc) dateFields.utc=true; | 258 if (utc) dateFields.utc=true; |
259 var stream = new _Stream(inputString); | 259 var stream = new _Stream(inputString); |
260 _formatFields.forEach( | 260 _formatFields.forEach( |
261 (each) => each.parse(stream, dateFields)); | 261 (each) => each.parse(stream, dateFields)); |
262 return dateFields.asDate(); | 262 return dateFields.asDate(); |
263 } | 263 } |
264 | 264 |
265 /** | 265 /** |
266 * Given user input, attempt to parse the [inputString] into the anticipated | 266 * Given user input, attempt to parse the [inputString] into the anticipated |
267 * format, treating it as being in UTC. | 267 * format, treating it as being in UTC. |
268 */ | 268 */ |
269 Date parseUTC(String inputString) { | 269 DateTime parseUTC(String inputString) { |
270 return parse(inputString, true); | 270 return parse(inputString, true); |
271 } | 271 } |
272 | 272 |
273 /** | 273 /** |
274 * Return the locale code in which we operate, e.g. 'en_US' or 'pt'. | 274 * Return the locale code in which we operate, e.g. 'en_US' or 'pt'. |
275 */ | 275 */ |
276 String get locale => _locale; | 276 String get locale => _locale; |
277 | 277 |
278 /** | 278 /** |
279 * Returns a list of all locales for which we have date formatting | 279 * Returns a list of all locales for which we have date formatting |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 List _reverse(List list) { | 589 List _reverse(List list) { |
590 // TODO(alanknight): Use standardized list reverse when implemented. | 590 // TODO(alanknight): Use standardized list reverse when implemented. |
591 // See Issue 2804. | 591 // See Issue 2804. |
592 var result = new List(); | 592 var result = new List(); |
593 for (var i = list.length-1; i >= 0; i--) { | 593 for (var i = list.length-1; i >= 0; i--) { |
594 result.addLast(list[i]); | 594 result.addLast(list[i]); |
595 } | 595 } |
596 return result; | 596 return result; |
597 } | 597 } |
598 } | 598 } |
OLD | NEW |