| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 _DateFormatQuotedField(pattern, parent): super(pattern, parent) { | 81 _DateFormatQuotedField(pattern, parent): super(pattern, parent) { |
| 82 _fullPattern = pattern; | 82 _fullPattern = pattern; |
| 83 patchQuotes(); | 83 patchQuotes(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 parse(_Stream input, _DateBuilder dateFields) { | 86 parse(_Stream input, _DateBuilder dateFields) { |
| 87 return parseLiteral(input); | 87 return parseLiteral(input); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void patchQuotes() { | 90 void patchQuotes() { |
| 91 if (pattern == "''") { | 91 if (pattern == "''") { |
| 92 pattern = "'"; | 92 pattern = "'"; |
| 93 } else { | 93 } else { |
| 94 pattern = pattern.substring(1, pattern.length - 1); | 94 pattern = pattern.substring(1, pattern.length - 1); |
| 95 var twoEscapedQuotes = new RegExp(r"''"); | 95 var twoEscapedQuotes = new RegExp(r"''"); |
| 96 pattern = pattern.replaceAll(twoEscapedQuotes, "'"); | 96 pattern = pattern.replaceAll(twoEscapedQuotes, "'"); |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 | 100 |
| 101 /* | 101 /* |
| 102 * Represents a field in the pattern that formats some aspect of the | 102 * Represents a field in the pattern that formats some aspect of the |
| 103 * date. Consists primarily of a switch on the particular pattern characters | 103 * date. Consists primarily of a switch on the particular pattern characters |
| 104 * to determine what to do. | 104 * to determine what to do. |
| 105 */ | 105 */ |
| 106 class _DateFormatPatternField extends _DateFormatField { | 106 class _DateFormatPatternField extends _DateFormatField { |
| 107 | 107 |
| 108 _DateFormatPatternField(pattern, parent): super(pattern, parent); | 108 _DateFormatPatternField(pattern, parent): super(pattern, parent); |
| 109 | 109 |
| 110 /** Format date according to our specification and return the result. */ | 110 /** Format date according to our specification and return the result. */ |
| 111 String format(DateTime date) { | 111 String format(DateTime date) { |
| 112 return formatField(date); | 112 return formatField(date); |
| 113 } | 113 } |
| 114 | 114 |
| 115 /** | 115 /** |
| 116 * Parse the date according to our specification and put the result | 116 * Parse the date according to our specification and put the result |
| 117 * into the correct place in dateFields. | 117 * into the correct place in dateFields. |
| 118 */ | 118 */ |
| 119 void parse(_Stream input, _DateBuilder dateFields) { | 119 void parse(_Stream input, _DateBuilder dateFields) { |
| 120 parseField(input, dateFields); | 120 parseField(input, dateFields); |
| 121 } | 121 } |
| 122 | 122 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 } | 411 } |
| 412 | 412 |
| 413 String formatTimeZone(DateTime date) { | 413 String formatTimeZone(DateTime date) { |
| 414 throw new UnimplementedError(); | 414 throw new UnimplementedError(); |
| 415 } | 415 } |
| 416 | 416 |
| 417 String formatTimeZoneRFC(DateTime date) { | 417 String formatTimeZoneRFC(DateTime date) { |
| 418 throw new UnimplementedError(); | 418 throw new UnimplementedError(); |
| 419 } | 419 } |
| 420 | 420 |
| 421 /** | 421 /** |
| 422 * Return a string representation of the object padded to the left with | 422 * Return a string representation of the object padded to the left with |
| 423 * zeros. Primarily useful for numbers. | 423 * zeros. Primarily useful for numbers. |
| 424 */ | 424 */ |
| 425 String padTo(int width, Object toBePrinted) { | 425 String padTo(int width, Object toBePrinted) { |
| 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 |