| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 IllegalArgumentException(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 = false]) { |
| 66 if (millisecondsSinceEpoch.abs() > _MAX_MILLISECONDS_SINCE_EPOCH) { | 66 if (millisecondsSinceEpoch.abs() > _MAX_MILLISECONDS_SINCE_EPOCH) { |
| 67 throw new IllegalArgumentException(millisecondsSinceEpoch); | 67 throw new IllegalArgumentException(millisecondsSinceEpoch); |
| 68 } | 68 } |
| 69 if (isUtc === null) throw new IllegalArgumentException(isUtc); | 69 if (isUtc === null) throw new IllegalArgumentException(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 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 ms - duration.inMilliseconds, isUtc); | 152 ms - duration.inMilliseconds, isUtc); |
| 153 } | 153 } |
| 154 | 154 |
| 155 /** Returns a [Duration] with the difference of [this] and [other]. */ | 155 /** Returns a [Duration] with the difference of [this] and [other]. */ |
| 156 Duration difference(Date other) { | 156 Duration difference(Date other) { |
| 157 int ms = millisecondsSinceEpoch; | 157 int ms = millisecondsSinceEpoch; |
| 158 int otherMs = other.millisecondsSinceEpoch; | 158 int otherMs = other.millisecondsSinceEpoch; |
| 159 return new Duration(milliseconds: ms - otherMs); | 159 return new Duration(milliseconds: ms - otherMs); |
| 160 } | 160 } |
| 161 | 161 |
| 162 // TODO(lrn): Make parameters not optional for the implementation class. | |
| 163 external DateImplementation(int year, | 162 external DateImplementation(int year, |
| 164 [int month = 1, | 163 [int month, |
| 165 int day = 1, | 164 int day, |
| 166 int hour = 0, | 165 int hour, |
| 167 int minute = 0, | 166 int minute, |
| 168 int second = 0, | 167 int second, |
| 169 int millisecond = 0, | 168 int millisecond, |
| 170 bool isUtc = false]); | 169 bool isUtc]); |
| 171 external DateImplementation.now(); | 170 external DateImplementation.now(); |
| 172 external static int _brokenDownDateToMillisecondsSinceEpoch( | 171 external static int _brokenDownDateToMillisecondsSinceEpoch( |
| 173 int years, int month, int day, int hour, int minute, int second, | 172 int years, int month, int day, int hour, int minute, int second, |
| 174 int millisecond, bool isUtc); | 173 int millisecond, bool isUtc); |
| 175 external String get timeZoneName; | 174 external String get timeZoneName; |
| 176 external Duration get timeZoneOffset; | 175 external Duration get timeZoneOffset; |
| 177 external int get year; | 176 external int get year; |
| 178 external int get month; | 177 external int get month; |
| 179 external int get day; | 178 external int get day; |
| 180 external int get hour; | 179 external int get hour; |
| 181 external int get minute; | 180 external int get minute; |
| 182 external int get second; | 181 external int get second; |
| 183 external int get millisecond; | 182 external int get millisecond; |
| 184 external int get weekday; | 183 external int get weekday; |
| 185 } | 184 } |
| OLD | NEW |