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