| 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 part of intl; | 6 part of intl; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * A class for holding onto the data for a date so that it can be built | 9 * A class for holding onto the data for a date so that it can be built |
| 10 * up incrementally. | 10 * up incrementally. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 void setSecond(x) { second = x; } | 32 void setSecond(x) { second = x; } |
| 33 void setFractionalSecond(x) { fractionalSecond = x; } | 33 void setFractionalSecond(x) { fractionalSecond = x; } |
| 34 | 34 |
| 35 /** | 35 /** |
| 36 * Return a date built using our values. If no date portion is set, | 36 * Return a date built using our values. If no date portion is set, |
| 37 * use the "Epoch" of January 1, 1970. | 37 * use the "Epoch" of January 1, 1970. |
| 38 */ | 38 */ |
| 39 DateTime asDate() { | 39 DateTime asDate() { |
| 40 // TODO(alanknight): Validate the date, especially for things which | 40 // TODO(alanknight): Validate the date, especially for things which |
| 41 // can crash the VM, e.g. large month values. | 41 // can crash the VM, e.g. large month values. |
| 42 if (debugLogDateCreation) { |
| 43 debugDateCreationLog |
| 44 ..write(" Creating Date from\n") |
| 45 ..write(" UTC: $utc\n") |
| 46 ..write(" year: $year\n") |
| 47 ..write(" month: $month\n") |
| 48 ..write(" day: $day\n") |
| 49 ..write(" pm: $pm\n") |
| 50 ..write(" hour: $hour\n") |
| 51 ..write(" minute: $minute\n") |
| 52 ..write(" second: $second\n") |
| 53 ..write(" fractionalSecond: $fractionalSecond\n"); |
| 54 } |
| 55 var result; |
| 42 if (utc) { | 56 if (utc) { |
| 43 return new DateTime.utc( | 57 result = new DateTime.utc( |
| 44 year, | 58 year, |
| 45 month, | 59 month, |
| 46 day, | 60 day, |
| 47 pm ? hour + 12 : hour, | 61 pm ? hour + 12 : hour, |
| 48 minute, | 62 minute, |
| 49 second, | 63 second, |
| 50 fractionalSecond); | 64 fractionalSecond); |
| 51 } else { | 65 } else { |
| 52 return new DateTime( | 66 result = new DateTime( |
| 53 year, | 67 year, |
| 54 month, | 68 month, |
| 55 day, | 69 day, |
| 56 pm ? hour + 12 : hour, | 70 pm ? hour + 12 : hour, |
| 57 minute, | 71 minute, |
| 58 second, | 72 second, |
| 59 fractionalSecond); | 73 fractionalSecond); |
| 60 } | 74 } |
| 75 if (debugLogDateCreation) { |
| 76 debugDateCreationLog |
| 77 ..write("Created $result"); |
| 78 } |
| 79 return result; |
| 61 } | 80 } |
| 62 } | 81 } |
| 63 | 82 |
| 64 /** | 83 /** |
| 65 * A simple and not particularly general stream class to make parsing | 84 * A simple and not particularly general stream class to make parsing |
| 66 * dates from strings simpler. It is general enough to operate on either | 85 * dates from strings simpler. It is general enough to operate on either |
| 67 * lists or strings. | 86 * lists or strings. |
| 68 */ | 87 */ |
| 69 class _Stream { | 88 class _Stream { |
| 70 var contents; | 89 var contents; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 * can see and then return the corresponding integer. Advance the stream. | 153 * can see and then return the corresponding integer. Advance the stream. |
| 135 */ | 154 */ |
| 136 var digitMatcher = new RegExp(r'\d+'); | 155 var digitMatcher = new RegExp(r'\d+'); |
| 137 int nextInteger() { | 156 int nextInteger() { |
| 138 var string = digitMatcher.stringMatch(rest()); | 157 var string = digitMatcher.stringMatch(rest()); |
| 139 if (string == null || string.isEmpty) return null; | 158 if (string == null || string.isEmpty) return null; |
| 140 read(string.length); | 159 read(string.length); |
| 141 return int.parse(string); | 160 return int.parse(string); |
| 142 } | 161 } |
| 143 } | 162 } |
| OLD | NEW |