| 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 /** | 7 /** |
| 8 * This is a private class internal to DateFormat which is used for formatting | 8 * This is a private class internal to DateFormat which is used for formatting |
| 9 * particular fields in a template. e.g. if the format is hh:mm:ss then the | 9 * particular fields in a template. e.g. if the format is hh:mm:ss then the |
| 10 * fields would be "hh", ":", "mm", ":", and "ss". Each type of field knows | 10 * fields would be "hh", ":", "mm", ":", and "ss". Each type of field knows |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 return width >= 4 ? symbols.ERANAMES[era] : | 188 return width >= 4 ? symbols.ERANAMES[era] : |
| 189 symbols.ERAS[era]; | 189 symbols.ERAS[era]; |
| 190 } | 190 } |
| 191 | 191 |
| 192 formatYear(DateTime date) { | 192 formatYear(DateTime date) { |
| 193 // TODO(alanknight): Proper handling of years <= 0 | 193 // TODO(alanknight): Proper handling of years <= 0 |
| 194 var year = date.year; | 194 var year = date.year; |
| 195 if (year < 0) { | 195 if (year < 0) { |
| 196 year = -year; | 196 year = -year; |
| 197 } | 197 } |
| 198 return width == 2 ? padTo(2, year % 100) : year.toString(); | 198 return width == 2 ? padTo(2, year % 100) : padTo(width, year); |
| 199 } | 199 } |
| 200 | 200 |
| 201 /** | 201 /** |
| 202 * We are given [input] as a stream from which we want to read a date. We | 202 * We are given [input] as a stream from which we want to read a date. We |
| 203 * can't dynamically build up a date, so we are given a list [dateFields] of | 203 * can't dynamically build up a date, so we are given a list [dateFields] of |
| 204 * the constructor arguments and an [position] at which to set it | 204 * the constructor arguments and an [position] at which to set it |
| 205 * (year,month,day,hour,minute,second,fractionalSecond) | 205 * (year,month,day,hour,minute,second,fractionalSecond) |
| 206 * then after all parsing is done we construct a date from the arguments. | 206 * then after all parsing is done we construct a date from the arguments. |
| 207 * This method handles reading any of the numeric fields. The [offset] | 207 * This method handles reading any of the numeric fields. The [offset] |
| 208 * argument allows us to compensate for zero-based versus one-based values. | 208 * argument allows us to compensate for zero-based versus one-based values. |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 var basicString = toBePrinted.toString(); | 426 var basicString = toBePrinted.toString(); |
| 427 if (basicString.length >= width) return basicString; | 427 if (basicString.length >= width) return basicString; |
| 428 var buffer = new StringBuffer(); | 428 var buffer = new StringBuffer(); |
| 429 for (var i = 0; i < width - basicString.length; i++) { | 429 for (var i = 0; i < width - basicString.length; i++) { |
| 430 buffer.write('0'); | 430 buffer.write('0'); |
| 431 } | 431 } |
| 432 buffer.write(basicString); | 432 buffer.write(basicString); |
| 433 return buffer.toString(); | 433 return buffer.toString(); |
| 434 } | 434 } |
| 435 } | 435 } |
| OLD | NEW |