| 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 * A class for holding onto the data for a date so that it can be built | 6 * A class for holding onto the data for a date so that it can be built |
| 7 * up incrementally. | 7 * up incrementally. |
| 8 */ | 8 */ |
| 9 class _DateBuilder { | 9 class _DateBuilder { |
| 10 // Default the date values to the EPOCH so that there's a valid date | 10 // Default the date values to the EPOCH so that there's a valid date |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 void setSecond(x) { second = x; } | 29 void setSecond(x) { second = x; } |
| 30 void setFractionalSecond(x) { fractionalSecond = x; } | 30 void setFractionalSecond(x) { fractionalSecond = x; } |
| 31 | 31 |
| 32 /** | 32 /** |
| 33 * Return a date built using our values. If no date portion is set, | 33 * Return a date built using our values. If no date portion is set, |
| 34 * use the "Epoch" of January 1, 1970. | 34 * use the "Epoch" of January 1, 1970. |
| 35 */ | 35 */ |
| 36 Date asDate() { | 36 Date asDate() { |
| 37 // TODO(alanknight): Validate the date, especially for things which | 37 // TODO(alanknight): Validate the date, especially for things which |
| 38 // can crash the VM, e.g. large month values. | 38 // can crash the VM, e.g. large month values. |
| 39 return new Date( | 39 if (utc) { |
| 40 year, | 40 return new Date.utc( |
| 41 month, | 41 year, |
| 42 day, | 42 month, |
| 43 pm ? hour + 12 : hour, | 43 day, |
| 44 minute, | 44 pm ? hour + 12 : hour, |
| 45 second, | 45 minute, |
| 46 fractionalSecond, | 46 second, |
| 47 utc); | 47 fractionalSecond); |
| 48 } else { |
| 49 return new Date( |
| 50 year, |
| 51 month, |
| 52 day, |
| 53 pm ? hour + 12 : hour, |
| 54 minute, |
| 55 second, |
| 56 fractionalSecond); |
| 57 } |
| 48 } | 58 } |
| 49 } | 59 } |
| 50 | 60 |
| 51 /** | 61 /** |
| 52 * A simple and not particularly general stream class to make parsing | 62 * A simple and not particularly general stream class to make parsing |
| 53 * dates from strings simpler. It is general enough to operate on either | 63 * dates from strings simpler. It is general enough to operate on either |
| 54 * lists or strings. | 64 * lists or strings. |
| 55 */ | 65 */ |
| 56 class _Stream { | 66 class _Stream { |
| 57 var contents; | 67 var contents; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 * can see and then return the corresponding integer. Advance the stream. | 131 * can see and then return the corresponding integer. Advance the stream. |
| 122 */ | 132 */ |
| 123 var digitMatcher = const RegExp(r'\d+'); | 133 var digitMatcher = const RegExp(r'\d+'); |
| 124 int nextInteger() { | 134 int nextInteger() { |
| 125 var string = digitMatcher.stringMatch(rest()); | 135 var string = digitMatcher.stringMatch(rest()); |
| 126 if (string == null || string.isEmpty()) return null; | 136 if (string == null || string.isEmpty()) return null; |
| 127 read(string.length); | 137 read(string.length); |
| 128 return int.parse(string); | 138 return int.parse(string); |
| 129 } | 139 } |
| 130 } | 140 } |
| OLD | NEW |