| 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 class DateImplementation implements Date { | 5 class DateImplementation implements Date { |
| 6 final int millisecondsSinceEpoch; | 6 final int millisecondsSinceEpoch; |
| 7 final bool isUtc; | 7 final bool isUtc; |
| 8 | 8 |
| 9 factory DateImplementation.fromString(String formattedString) { | 9 factory DateImplementation.fromString(String formattedString) { |
| 10 // Read in (a subset of) ISO 8601. | 10 // Read in (a subset of) ISO 8601. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 int millisecond = (parseDoubleOrZero(match[7]) * 1000).round().toInt(); | 43 int millisecond = (parseDoubleOrZero(match[7]) * 1000).round().toInt(); |
| 44 if (millisecond == 1000) { | 44 if (millisecond == 1000) { |
| 45 addOneMillisecond = true; | 45 addOneMillisecond = true; |
| 46 millisecond = 999; | 46 millisecond = 999; |
| 47 } | 47 } |
| 48 // TODO(floitsch): we should not need to test against the empty string. | 48 // TODO(floitsch): we should not need to test against the empty string. |
| 49 bool isUtc = (match[8] !== null) && (match[8] != ""); | 49 bool isUtc = (match[8] !== null) && (match[8] != ""); |
| 50 int millisecondsSinceEpoch = _brokenDownDateToMillisecondsSinceEpoch( | 50 int millisecondsSinceEpoch = _brokenDownDateToMillisecondsSinceEpoch( |
| 51 years, month, day, hour, minute, second, millisecond, isUtc); | 51 years, month, day, hour, minute, second, millisecond, isUtc); |
| 52 if (millisecondsSinceEpoch === null) { | 52 if (millisecondsSinceEpoch === null) { |
| 53 throw new IllegalArgumentException(formattedString); | 53 throw new ArgumentError(formattedString); |
| 54 } | 54 } |
| 55 if (addOneMillisecond) millisecondsSinceEpoch++; | 55 if (addOneMillisecond) millisecondsSinceEpoch++; |
| 56 return new Date.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, isUtc); | 56 return new Date.fromMillisecondsSinceEpoch(millisecondsSinceEpoch, isUtc); |
| 57 } else { | 57 } else { |
| 58 throw new IllegalArgumentException(formattedString); | 58 throw new ArgumentError(formattedString); |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 static const int _MAX_MILLISECONDS_SINCE_EPOCH = 8640000000000000; | 62 static const int _MAX_MILLISECONDS_SINCE_EPOCH = 8640000000000000; |
| 63 | 63 |
| 64 DateImplementation.fromMillisecondsSinceEpoch(this.millisecondsSinceEpoch, | 64 DateImplementation.fromMillisecondsSinceEpoch(this.millisecondsSinceEpoch, |
| 65 this.isUtc) { | 65 this.isUtc) { |
| 66 if (millisecondsSinceEpoch.abs() > _MAX_MILLISECONDS_SINCE_EPOCH) { | 66 if (millisecondsSinceEpoch.abs() > _MAX_MILLISECONDS_SINCE_EPOCH) { |
| 67 throw new IllegalArgumentException(millisecondsSinceEpoch); | 67 throw new ArgumentError(millisecondsSinceEpoch); |
| 68 } | 68 } |
| 69 if (isUtc === null) throw new IllegalArgumentException(isUtc); | 69 if (isUtc === null) throw new ArgumentError(isUtc); |
| 70 } | 70 } |
| 71 | 71 |
| 72 bool operator ==(other) { | 72 bool operator ==(other) { |
| 73 if (!(other is Date)) return false; | 73 if (!(other is Date)) return false; |
| 74 return (millisecondsSinceEpoch == other.millisecondsSinceEpoch); | 74 return (millisecondsSinceEpoch == other.millisecondsSinceEpoch); |
| 75 } | 75 } |
| 76 | 76 |
| 77 bool operator <(Date other) | 77 bool operator <(Date other) |
| 78 => millisecondsSinceEpoch < other.millisecondsSinceEpoch; | 78 => millisecondsSinceEpoch < other.millisecondsSinceEpoch; |
| 79 | 79 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 external Duration get timeZoneOffset; | 176 external Duration get timeZoneOffset; |
| 177 external int get year; | 177 external int get year; |
| 178 external int get month; | 178 external int get month; |
| 179 external int get day; | 179 external int get day; |
| 180 external int get hour; | 180 external int get hour; |
| 181 external int get minute; | 181 external int get minute; |
| 182 external int get second; | 182 external int get second; |
| 183 external int get millisecond; | 183 external int get millisecond; |
| 184 external int get weekday; | 184 external int get weekday; |
| 185 } | 185 } |
| OLD | NEW |