| 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 // Dart core library. | 4 // Dart core library. |
| 5 | 5 |
| 6 // VM implementation of _DateImpl. | 6 // VM implementation of DateTime. |
| 7 patch class _DateImpl { | 7 patch class DateTime { |
| 8 /* patch */ _DateImpl(int year, | 8 /* patch */ DateTime._internal(int year, |
| 9 int month, | 9 int month, |
| 10 int day, | 10 int day, |
| 11 int hour, | 11 int hour, |
| 12 int minute, | 12 int minute, |
| 13 int second, | 13 int second, |
| 14 int millisecond, | 14 int millisecond, |
| 15 bool isUtc) | 15 bool isUtc) |
| 16 : this.isUtc = isUtc, | 16 : this.isUtc = isUtc, |
| 17 this.millisecondsSinceEpoch = _brokenDownDateToMillisecondsSinceEpoch( | 17 this.millisecondsSinceEpoch = _brokenDownDateToMillisecondsSinceEpoch( |
| 18 year, month, day, hour, minute, second, millisecond, isUtc) { | 18 year, month, day, hour, minute, second, millisecond, isUtc) { |
| 19 if (millisecondsSinceEpoch == null) throw new ArgumentError(); | 19 if (millisecondsSinceEpoch == null) throw new ArgumentError(); |
| 20 if (isUtc == null) throw new ArgumentError(); | 20 if (isUtc == null) throw new ArgumentError(); |
| 21 } | 21 } |
| 22 | 22 |
| 23 /* patch */ _DateImpl.now() | 23 /* patch */ DateTime._now() |
| 24 : isUtc = false, | 24 : isUtc = false, |
| 25 millisecondsSinceEpoch = _getCurrentMs() { | 25 millisecondsSinceEpoch = _getCurrentMs() { |
| 26 } | 26 } |
| 27 | 27 |
| 28 /* patch */ String get timeZoneName { | 28 /* patch */ String get timeZoneName { |
| 29 if (isUtc) return "UTC"; | 29 if (isUtc) return "UTC"; |
| 30 return _timeZoneName(millisecondsSinceEpoch); | 30 return _timeZoneName(millisecondsSinceEpoch); |
| 31 } | 31 } |
| 32 | 32 |
| 33 /* patch */ Duration get timeZoneOffset { | 33 /* patch */ Duration get timeZoneOffset { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // directly use the value and not the [_localDateInUtcValue]. | 68 // directly use the value and not the [_localDateInUtcValue]. |
| 69 return millisecondsSinceEpoch % Duration.MILLISECONDS_PER_SECOND; | 69 return millisecondsSinceEpoch % Duration.MILLISECONDS_PER_SECOND; |
| 70 } | 70 } |
| 71 | 71 |
| 72 /** Returns the weekday of [this]. In accordance with ISO 8601 a week | 72 /** Returns the weekday of [this]. In accordance with ISO 8601 a week |
| 73 * starts with Monday. Monday has the value 1 up to Sunday with 7. */ | 73 * starts with Monday. Monday has the value 1 up to Sunday with 7. */ |
| 74 /* patch */ int get weekday { | 74 /* patch */ int get weekday { |
| 75 int daysSince1970 = | 75 int daysSince1970 = |
| 76 _flooredDivision(_localDateInUtcMs, Duration.MILLISECONDS_PER_DAY); | 76 _flooredDivision(_localDateInUtcMs, Duration.MILLISECONDS_PER_DAY); |
| 77 // 1970-1-1 was a Thursday. | 77 // 1970-1-1 was a Thursday. |
| 78 return ((daysSince1970 + Date.THU - Date.MON) % Date.DAYS_IN_WEEK) + | 78 return ((daysSince1970 + DateTime.THU - DateTime.MON) % DateTime.DAYS_IN_WEE
K) + |
| 79 Date.MON; | 79 DateTime.MON; |
| 80 } | 80 } |
| 81 | 81 |
| 82 | 82 |
| 83 /** The first list contains the days until each month in non-leap years. The | 83 /** The first list contains the days until each month in non-leap years. The |
| 84 * second list contains the days in leap years. */ | 84 * second list contains the days in leap years. */ |
| 85 static const List<List<int>> _DAYS_UNTIL_MONTH = | 85 static const List<List<int>> _DAYS_UNTIL_MONTH = |
| 86 const [const [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334], | 86 const [const [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334], |
| 87 const [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335]]; | 87 const [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335]]; |
| 88 | 88 |
| 89 // Returns the UTC year, month and day for the corresponding | 89 // Returns the UTC year, month and day for the corresponding |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 } | 133 } |
| 134 resultDay = days - daysUntilMonth[resultMonth - 1] + 1; | 134 resultDay = days - daysUntilMonth[resultMonth - 1] + 1; |
| 135 return <int>[resultYear, resultMonth, resultDay]; | 135 return <int>[resultYear, resultMonth, resultDay]; |
| 136 } | 136 } |
| 137 | 137 |
| 138 /** | 138 /** |
| 139 * Returns the amount of milliseconds in UTC that represent the same values | 139 * Returns the amount of milliseconds in UTC that represent the same values |
| 140 * as [this]. | 140 * as [this]. |
| 141 * | 141 * |
| 142 * Say [:t:] is the result of this function, then | 142 * Say [:t:] is the result of this function, then |
| 143 * * [:this.year == new Date.fromMillisecondsSinceEpoch(t, true).year:], | 143 * * [:this.year == new DateTime.fromMillisecondsSinceEpoch(t, true).year:], |
| 144 * * [:this.month == new Date.fromMillisecondsSinceEpoch(t, true).month:], | 144 * * [:this.month == new DateTime.fromMillisecondsSinceEpoch(t, true).month:], |
| 145 * * [:this.day == new Date.fromMillisecondsSinceEpoch(t, true).day:], | 145 * * [:this.day == new DateTime.fromMillisecondsSinceEpoch(t, true).day:], |
| 146 * * [:this.hour == new Date.fromMillisecondsSinceEpoch(t, true).hour:], | 146 * * [:this.hour == new DateTime.fromMillisecondsSinceEpoch(t, true).hour:], |
| 147 * * ... | 147 * * ... |
| 148 * | 148 * |
| 149 * Daylight savings is computed as if the date was computed in [1970..2037]. | 149 * Daylight savings is computed as if the date was computed in [1970..2037]. |
| 150 * If [this] lies outside this range then it is a year with similar | 150 * If [this] lies outside this range then it is a year with similar |
| 151 * properties (leap year, weekdays) is used instead. | 151 * properties (leap year, weekdays) is used instead. |
| 152 */ | 152 */ |
| 153 int get _localDateInUtcMs { | 153 int get _localDateInUtcMs { |
| 154 int ms = millisecondsSinceEpoch; | 154 int ms = millisecondsSinceEpoch; |
| 155 if (isUtc) return ms; | 155 if (isUtc) return ms; |
| 156 int offset = | 156 int offset = |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 | 315 |
| 316 static String _timeZoneNameForClampedSeconds(int secondsSinceEpoch) | 316 static String _timeZoneNameForClampedSeconds(int secondsSinceEpoch) |
| 317 native "DateNatives_timeZoneName"; | 317 native "DateNatives_timeZoneName"; |
| 318 | 318 |
| 319 static int _timeZoneOffsetInSecondsForClampedSeconds(int secondsSinceEpoch) | 319 static int _timeZoneOffsetInSecondsForClampedSeconds(int secondsSinceEpoch) |
| 320 native "DateNatives_timeZoneOffsetInSeconds"; | 320 native "DateNatives_timeZoneOffsetInSeconds"; |
| 321 | 321 |
| 322 static int _localTimeZoneAdjustmentInSeconds() | 322 static int _localTimeZoneAdjustmentInSeconds() |
| 323 native "DateNatives_localTimeZoneAdjustmentInSeconds"; | 323 native "DateNatives_localTimeZoneAdjustmentInSeconds"; |
| 324 } | 324 } |
| OLD | NEW |