| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // Dart core library. | 4 // Dart core library. |
| 5 | 5 |
| 6 class TimeZoneImplementation implements TimeZone { | 6 class TimeZoneImplementation implements TimeZone { |
| 7 const TimeZoneImplementation.utc() : isUtc = true; | 7 const TimeZoneImplementation.utc() : isUtc = true; |
| 8 TimeZoneImplementation.local() : isUtc = false {} | 8 TimeZoneImplementation.local() : isUtc = false {} |
| 9 | 9 |
| 10 bool operator ==(Object other) { | 10 bool operator ==(Object other) { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 int compareTo(Date other) => value.compareTo(other.value); | 123 int compareTo(Date other) => value.compareTo(other.value); |
| 124 int hashCode() => value; | 124 int hashCode() => value; |
| 125 | 125 |
| 126 Date changeTimeZone(TimeZone targetTimeZone) { | 126 Date changeTimeZone(TimeZone targetTimeZone) { |
| 127 if (targetTimeZone === null) { | 127 if (targetTimeZone === null) { |
| 128 targetTimeZone = new TimeZoneImplementation.local(); | 128 targetTimeZone = new TimeZoneImplementation.local(); |
| 129 } | 129 } |
| 130 return new Date.fromEpoch(value, targetTimeZone); | 130 return new Date.fromEpoch(value, targetTimeZone); |
| 131 } | 131 } |
| 132 | 132 |
| 133 String get timeZoneName() { |
| 134 if (isUtc()) return "UTC"; |
| 135 return _timeZoneName(_equivalentSeconds(_secondsSinceEpoch)); |
| 136 } |
| 137 |
| 138 Duration get timeZoneOffset() { |
| 139 if (isUtc()) return new Duration(0); |
| 140 int offsetInSeconds = |
| 141 _timeZoneOffsetInSeconds(_equivalentSeconds(_secondsSinceEpoch)); |
| 142 return new Duration(seconds: offsetInSeconds); |
| 143 } |
| 144 |
| 133 int get year() { | 145 int get year() { |
| 134 int secondsSinceEpoch = _secondsSinceEpoch; | 146 int secondsSinceEpoch = _secondsSinceEpoch; |
| 135 // According to V8 some library calls have troubles with negative values. | 147 // According to V8 some library calls have troubles with negative values. |
| 136 // Therefore clamp to 0 - year 2035 (which is less than the size of 32bit). | 148 // Therefore clamp to 0 - year 2035 (which is less than the size of 32bit). |
| 137 if (secondsSinceEpoch >= 0 && secondsSinceEpoch < _SECONDS_YEAR_2035) { | 149 if (secondsSinceEpoch >= 0 && secondsSinceEpoch < _SECONDS_YEAR_2035) { |
| 138 return _getYear(secondsSinceEpoch, timeZone.isUtc); | 150 return _getYear(secondsSinceEpoch, timeZone.isUtc); |
| 139 } | 151 } |
| 140 | 152 |
| 141 // Approximate the result. We don't take timeZone into account. | 153 // Approximate the result. We don't take timeZone into account. |
| 142 int approximateYear = _yearsFromSecondsSinceEpoch(secondsSinceEpoch); | 154 int approximateYear = _yearsFromSecondsSinceEpoch(secondsSinceEpoch); |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 return adjustedSeconds * Duration.MILLISECONDS_PER_SECOND + milliseconds; | 406 return adjustedSeconds * Duration.MILLISECONDS_PER_SECOND + milliseconds; |
| 395 } | 407 } |
| 396 | 408 |
| 397 // Natives | 409 // Natives |
| 398 static _brokenDownDateToSecondsSinceEpoch( | 410 static _brokenDownDateToSecondsSinceEpoch( |
| 399 int years, int month, int day, int hours, int minutes, int seconds, | 411 int years, int month, int day, int hours, int minutes, int seconds, |
| 400 bool isUtc) native "DateNatives_brokenDownToSecondsSinceEpoch"; | 412 bool isUtc) native "DateNatives_brokenDownToSecondsSinceEpoch"; |
| 401 | 413 |
| 402 static int _getCurrentMs() native "DateNatives_currentTimeMillis"; | 414 static int _getCurrentMs() native "DateNatives_currentTimeMillis"; |
| 403 | 415 |
| 416 static String _timeZoneName(int secondsSinceEpoch) |
| 417 native "DateNatives_timeZoneName"; |
| 418 |
| 419 static int _timeZoneOffsetInSeconds(int secondsSinceEpoch) |
| 420 native "DateNatives_timeZoneOffsetInSeconds"; |
| 421 |
| 404 // TODO(floitsch): it would be more efficient if we didn't call the native | 422 // TODO(floitsch): it would be more efficient if we didn't call the native |
| 405 // function for every member, but cached the broken-down date. | 423 // function for every member, but cached the broken-down date. |
| 406 static int _getYear(int secondsSinceEpoch, bool isUtc) | 424 static int _getYear(int secondsSinceEpoch, bool isUtc) |
| 407 native "DateNatives_getYear"; | 425 native "DateNatives_getYear"; |
| 408 | 426 |
| 409 static int _getMonth(int secondsSinceEpoch, bool isUtc) | 427 static int _getMonth(int secondsSinceEpoch, bool isUtc) |
| 410 native "DateNatives_getMonth"; | 428 native "DateNatives_getMonth"; |
| 411 | 429 |
| 412 static int _getDay(int secondsSinceEpoch, bool isUtc) | 430 static int _getDay(int secondsSinceEpoch, bool isUtc) |
| 413 native "DateNatives_getDay"; | 431 native "DateNatives_getDay"; |
| 414 | 432 |
| 415 static int _getHours(int secondsSinceEpoch, bool isUtc) | 433 static int _getHours(int secondsSinceEpoch, bool isUtc) |
| 416 native "DateNatives_getHours"; | 434 native "DateNatives_getHours"; |
| 417 | 435 |
| 418 static int _getMinutes(int secondsSinceEpoch, bool isUtc) | 436 static int _getMinutes(int secondsSinceEpoch, bool isUtc) |
| 419 native "DateNatives_getMinutes"; | 437 native "DateNatives_getMinutes"; |
| 420 | 438 |
| 421 static int _getSeconds(int secondsSinceEpoch, bool isUtc) | 439 static int _getSeconds(int secondsSinceEpoch, bool isUtc) |
| 422 native "DateNatives_getSeconds"; | 440 native "DateNatives_getSeconds"; |
| 423 } | 441 } |
| OLD | NEW |