Chromium Code Reviews| 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 int year = 0, | 10 int year = 0, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 void setYear(x) { year = x; } | 22 void setYear(x) { year = x; } |
| 23 void setMonth(x) { month = x; } | 23 void setMonth(x) { month = x; } |
| 24 void setDay(x) { day = x; } | 24 void setDay(x) { day = x; } |
| 25 void setHour(x) { hour = x; } | 25 void setHour(x) { hour = x; } |
| 26 void setMinute(x) { minute = x; } | 26 void setMinute(x) { minute = x; } |
| 27 void setSecond(x) { second = x; } | 27 void setSecond(x) { second = x; } |
| 28 void setFractionalSecond(x) { fractionalSecond = x; } | 28 void setFractionalSecond(x) { fractionalSecond = x; } |
| 29 | 29 |
| 30 /** | 30 /** |
| 31 * Return a date built using our values. If no date portion is set, | 31 * Return a date built using our values. If no date portion is set, |
| 32 * use today's date, as otherwise the constructor will fail. | 32 * use the "Epoch" (January 1, 1970), since the constructor will fail if |
|
Anton Muhin
2012/08/30 17:44:03
nit: I think "since the constructor..." can be omi
Alan Knight
2012/08/30 17:50:40
Done.
| |
| 33 * given zero values for those fields. | |
| 33 */ | 34 */ |
| 34 Date asDate() { | 35 Date asDate() { |
| 35 if (year == 0 || month == 0 || day == 0) { | 36 if (year == 0 || month == 0 || day == 0) { |
| 36 var today = new Date.now(); | 37 if (year == 0) year = 1970; |
|
Anton Muhin
2012/08/30 17:44:03
maybe just make those default values for fields?
Alan Knight
2012/08/30 17:50:40
Yes, that's much nicer. Done.
| |
| 37 if (year == 0) year = today.year; | 38 if (month == 0) month = 1; |
| 38 if (month == 0) month = today.month; | 39 if (day == 0) day = 1; |
| 39 if (day == 0) day = today.day; | |
| 40 } | 40 } |
| 41 | 41 |
| 42 // TODO(alanknight): Validate the date, especially for things which | 42 // TODO(alanknight): Validate the date, especially for things which |
| 43 // can crash the VM, e.g. large month values. | 43 // can crash the VM, e.g. large month values. |
| 44 return new Date( | 44 return new Date( |
| 45 year, | 45 year, |
| 46 month, | 46 month, |
| 47 day, | 47 day, |
| 48 pm ? hour + 12 : hour, | 48 pm ? hour + 12 : hour, |
| 49 minute, | 49 minute, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 * can see and then return the corresponding integer. Advance the stream. | 126 * can see and then return the corresponding integer. Advance the stream. |
| 127 */ | 127 */ |
| 128 var digitMatcher = const RegExp(@'\d+'); | 128 var digitMatcher = const RegExp(@'\d+'); |
| 129 int nextInteger() { | 129 int nextInteger() { |
| 130 var string = digitMatcher.stringMatch(rest()); | 130 var string = digitMatcher.stringMatch(rest()); |
| 131 if (string == null || string.isEmpty()) return null; | 131 if (string == null || string.isEmpty()) return null; |
| 132 read(string.length); | 132 read(string.length); |
| 133 return parseInt(string); | 133 return parseInt(string); |
| 134 } | 134 } |
| 135 } | 135 } |
| OLD | NEW |