| 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 { |
| 7 const TimeZoneImplementation.utc() : isUtc = true; |
| 8 TimeZoneImplementation.local() : isUtc = false {} |
| 9 |
| 10 bool operator ==(Object other) { |
| 11 if (!(other is TimeZoneImplementation)) return false; |
| 12 return isUtc == other.isUtc; |
| 13 } |
| 14 |
| 15 final bool isUtc; |
| 16 } |
| 17 |
| 6 // VM implementation of DateImplementation. | 18 // VM implementation of DateImplementation. |
| 7 class DateImplementation implements Date { | 19 class DateImplementation implements Date { |
| 8 static final int _SECONDS_YEAR_2035 = 2051222400; | 20 static final int _SECONDS_YEAR_2035 = 2051222400; |
| 9 | 21 |
| 10 DateImplementation(int years, | 22 DateImplementation(int years, |
| 11 [int month = 1, | 23 [int month = 1, |
| 12 int day = 1, | 24 int day = 1, |
| 13 int hours = 0, | 25 int hours = 0, |
| 14 int minutes = 0, | 26 int minutes = 0, |
| 15 int seconds = 0, | 27 int seconds = 0, |
| 16 int milliseconds = 0, | 28 int milliseconds = 0, |
| 17 bool isUtc = false]) | 29 bool isUtc = false]) |
| 18 : _isUtc = isUtc, | 30 : _isUtc = isUtc, |
| 19 value = _brokenDownDateToMillisecondsSinceEpoch( | 31 value = _brokenDownDateToMillisecondsSinceEpoch( |
| 20 years, month, day, hours, minutes, seconds, milliseconds, isUtc) { | 32 years, month, day, hours, minutes, seconds, milliseconds, isUtc) { |
| 21 if (value === null) throw new IllegalArgumentException(); | 33 if (value === null) throw new IllegalArgumentException(); |
| 22 } | 34 } |
| 23 | 35 |
| 36 DateImplementation.withTimeZone(int years, |
| 37 int month, |
| 38 int day, |
| 39 int hours, |
| 40 int minutes, |
| 41 int seconds, |
| 42 int milliseconds, |
| 43 TimeZone timeZone) |
| 44 : this(years, month, day, hours, minutes, seconds, milliseconds, |
| 45 timeZone.isUtc); |
| 46 |
| 24 DateImplementation.now() | 47 DateImplementation.now() |
| 25 : _isUtc = true, | 48 : _isUtc = true, |
| 26 value = _getCurrentMs() { | 49 value = _getCurrentMs() { |
| 27 } | 50 } |
| 28 | 51 |
| 29 factory DateImplementation.fromString(String formattedString) { | 52 factory DateImplementation.fromString(String formattedString) { |
| 30 // Read in (a subset of) ISO 8601. | 53 // Read in (a subset of) ISO 8601. |
| 31 // Examples: | 54 // Examples: |
| 32 // - "2012-02-27 13:27:00" | 55 // - "2012-02-27 13:27:00" |
| 33 // - "2012-02-27 13:27:00.423z" | 56 // - "2012-02-27 13:27:00.423z" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 Date toLocal() { | 124 Date toLocal() { |
| 102 if (isUtc()) return new DateImplementation.fromEpoch(value, false); | 125 if (isUtc()) return new DateImplementation.fromEpoch(value, false); |
| 103 return this; | 126 return this; |
| 104 } | 127 } |
| 105 | 128 |
| 106 Date toUtc() { | 129 Date toUtc() { |
| 107 if (isUtc()) return this; | 130 if (isUtc()) return this; |
| 108 return new DateImplementation.fromEpoch(value, true); | 131 return new DateImplementation.fromEpoch(value, true); |
| 109 } | 132 } |
| 110 | 133 |
| 134 Date changeTimeZone(TimeZone targetTimeZone) { |
| 135 if (targetTimeZone === null) { |
| 136 targetTimeZone = new TimeZoneImplementation.local(); |
| 137 } |
| 138 return new Date.fromEpoch(value, targetTimeZone.isUtc); |
| 139 } |
| 140 |
| 111 String get timeZoneName() { | 141 String get timeZoneName() { |
| 112 if (isUtc()) return "UTC"; | 142 if (isUtc()) return "UTC"; |
| 113 return _timeZoneName(_equivalentSeconds(_secondsSinceEpoch)); | 143 return _timeZoneName(_equivalentSeconds(_secondsSinceEpoch)); |
| 114 } | 144 } |
| 115 | 145 |
| 116 Duration get timeZoneOffset() { | 146 Duration get timeZoneOffset() { |
| 117 if (isUtc()) return new Duration(0); | 147 if (isUtc()) return new Duration(0); |
| 118 int offsetInSeconds = | 148 int offsetInSeconds = |
| 119 _timeZoneOffsetInSeconds(_equivalentSeconds(_secondsSinceEpoch)); | 149 _timeZoneOffsetInSeconds(_equivalentSeconds(_secondsSinceEpoch)); |
| 120 return new Duration(seconds: offsetInSeconds); | 150 return new Duration(seconds: offsetInSeconds); |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 | 432 |
| 403 static int _getHours(int secondsSinceEpoch, bool isUtc) | 433 static int _getHours(int secondsSinceEpoch, bool isUtc) |
| 404 native "DateNatives_getHours"; | 434 native "DateNatives_getHours"; |
| 405 | 435 |
| 406 static int _getMinutes(int secondsSinceEpoch, bool isUtc) | 436 static int _getMinutes(int secondsSinceEpoch, bool isUtc) |
| 407 native "DateNatives_getMinutes"; | 437 native "DateNatives_getMinutes"; |
| 408 | 438 |
| 409 static int _getSeconds(int secondsSinceEpoch, bool isUtc) | 439 static int _getSeconds(int secondsSinceEpoch, bool isUtc) |
| 410 native "DateNatives_getSeconds"; | 440 native "DateNatives_getSeconds"; |
| 411 } | 441 } |
| OLD | NEW |