| 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 // Mocks of classes and interfaces that Leg cannot read directly. | 5 // Mocks of classes and interfaces that Leg cannot read directly. |
| 6 | 6 |
| 7 // TODO(ahe): Remove this file. | 7 // TODO(ahe): Remove this file. |
| 8 | 8 |
| 9 class JSSyntaxRegExp implements RegExp { | 9 class JSSyntaxRegExp implements RegExp { |
| 10 final String pattern; | 10 final String pattern; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 var result = ""; | 159 var result = ""; |
| 160 for (var string in strings) { | 160 for (var string in strings) { |
| 161 checkNull(string); | 161 checkNull(string); |
| 162 if (string is !String) throw new IllegalArgumentException(string); | 162 if (string is !String) throw new IllegalArgumentException(string); |
| 163 result += string; // TODO(ahe): Use string buffer. | 163 result += string; // TODO(ahe): Use string buffer. |
| 164 } | 164 } |
| 165 return result; | 165 return result; |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 | 168 |
| 169 class TimeZoneImplementation implements TimeZone { | |
| 170 const TimeZoneImplementation.utc() : isUtc = true; | |
| 171 TimeZoneImplementation.local() : isUtc = false; | |
| 172 | |
| 173 bool operator ==(Object other) { | |
| 174 if (!(other is TimeZoneImplementation)) return false; | |
| 175 return isUtc == other.isUtc; | |
| 176 } | |
| 177 | |
| 178 final bool isUtc; | |
| 179 } | |
| 180 | |
| 181 class DateImplementation implements Date { | 169 class DateImplementation implements Date { |
| 182 final int value; | 170 final int value; |
| 183 final bool _isUtc; | 171 final bool _isUtc; |
| 184 | 172 |
| 185 DateImplementation(int years, | 173 DateImplementation(int years, |
| 186 [int month = 1, | 174 [int month = 1, |
| 187 int day = 1, | 175 int day = 1, |
| 188 int hours = 0, | 176 int hours = 0, |
| 189 int minutes = 0, | 177 int minutes = 0, |
| 190 int seconds = 0, | 178 int seconds = 0, |
| 191 int milliseconds = 0, | 179 int milliseconds = 0, |
| 192 bool isUtc = false]) | 180 bool isUtc = false]) |
| 193 : this._isUtc = checkNull(isUtc), | 181 : this._isUtc = checkNull(isUtc), |
| 194 value = Primitives.valueFromDecomposedDate( | 182 value = Primitives.valueFromDecomposedDate( |
| 195 years, month, day, hours, minutes, seconds, milliseconds, isUtc) { | 183 years, month, day, hours, minutes, seconds, milliseconds, isUtc) { |
| 196 _asJs(); | 184 _asJs(); |
| 197 } | 185 } |
| 198 | 186 |
| 199 DateImplementation.withTimeZone(int years, | |
| 200 int month, | |
| 201 int day, | |
| 202 int hours, | |
| 203 int minutes, | |
| 204 int seconds, | |
| 205 int milliseconds, | |
| 206 TimeZoneImplementation timeZone) | |
| 207 : this(years, month, day, hours, minutes, seconds, milliseconds, | |
| 208 timeZone.isUtc); | |
| 209 | |
| 210 DateImplementation.now() | 187 DateImplementation.now() |
| 211 : _isUtc = false, | 188 : _isUtc = false, |
| 212 value = Primitives.dateNow() { | 189 value = Primitives.dateNow() { |
| 213 _asJs(); | 190 _asJs(); |
| 214 } | 191 } |
| 215 | 192 |
| 216 factory DateImplementation.fromString(String formattedString) { | 193 factory DateImplementation.fromString(String formattedString) { |
| 217 // Read in (a subset of) ISO 8601. | 194 // Read in (a subset of) ISO 8601. |
| 218 // Examples: | 195 // Examples: |
| 219 // - "2012-02-27 13:27:00" | 196 // - "2012-02-27 13:27:00" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 Date toLocal() { | 266 Date toLocal() { |
| 290 if (isUtc()) return new DateImplementation.fromEpoch(value, false); | 267 if (isUtc()) return new DateImplementation.fromEpoch(value, false); |
| 291 return this; | 268 return this; |
| 292 } | 269 } |
| 293 | 270 |
| 294 Date toUtc() { | 271 Date toUtc() { |
| 295 if (isUtc()) return this; | 272 if (isUtc()) return this; |
| 296 return new DateImplementation.fromEpoch(value, true); | 273 return new DateImplementation.fromEpoch(value, true); |
| 297 } | 274 } |
| 298 | 275 |
| 299 Date changeTimeZone(TimeZone targetTimeZone) { | |
| 300 if (targetTimeZone === null) { | |
| 301 targetTimeZone = new TimeZoneImplementation.local(); | |
| 302 } | |
| 303 return new Date.fromEpoch(value, targetTimeZone.isUtc); | |
| 304 } | |
| 305 | |
| 306 String get timeZoneName() { | 276 String get timeZoneName() { |
| 307 if (isUtc()) return "UTC"; | 277 if (isUtc()) return "UTC"; |
| 308 return Primitives.getTimeZoneName(this); | 278 return Primitives.getTimeZoneName(this); |
| 309 } | 279 } |
| 310 | 280 |
| 311 Duration get timeZoneOffset() { | 281 Duration get timeZoneOffset() { |
| 312 if (isUtc()) return new Duration(0); | 282 if (isUtc()) return new Duration(0); |
| 313 return new Duration(minutes: Primitives.getTimeZoneOffsetInMinutes(this)); | 283 return new Duration(minutes: Primitives.getTimeZoneOffsetInMinutes(this)); |
| 314 } | 284 } |
| 315 | 285 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 factory List.from(Iterable<E> other) { | 370 factory List.from(Iterable<E> other) { |
| 401 List<E> result = new List<E>(); | 371 List<E> result = new List<E>(); |
| 402 // TODO(ahe): Use for-in when it is implemented correctly. | 372 // TODO(ahe): Use for-in when it is implemented correctly. |
| 403 Iterator<E> iterator = other.iterator(); | 373 Iterator<E> iterator = other.iterator(); |
| 404 while (iterator.hasNext()) { | 374 while (iterator.hasNext()) { |
| 405 result.add(iterator.next()); | 375 result.add(iterator.next()); |
| 406 } | 376 } |
| 407 return result; | 377 return result; |
| 408 } | 378 } |
| 409 } | 379 } |
| OLD | NEW |