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 DateTime. | 6 // VM implementation of DateTime. |
7 patch class DateTime { | 7 patch class DateTime { |
8 // Natives. | 8 // Natives. |
9 // The natives have been moved up here to work around Issue 10401. | 9 // The natives have been moved up here to work around Issue 10401. |
10 static int _getCurrentMs() native "DateNatives_currentTimeMillis"; | 10 static int _getCurrentMs() native "DateNatives_currentTimeMillis"; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 + _flooredDivision(year - 1969, 4) | 183 + _flooredDivision(year - 1969, 4) |
184 - _flooredDivision(year - 1901, 100) | 184 - _flooredDivision(year - 1901, 100) |
185 + _flooredDivision(year - 1601, 400); | 185 + _flooredDivision(year - 1601, 400); |
186 } | 186 } |
187 | 187 |
188 static bool _isLeapYear(y) { | 188 static bool _isLeapYear(y) { |
189 return (y.remainder(4) == 0) && | 189 return (y.remainder(4) == 0) && |
190 ((y.remainder(100) != 0) || (y.remainder(400) == 0)); | 190 ((y.remainder(100) != 0) || (y.remainder(400) == 0)); |
191 } | 191 } |
192 | 192 |
193 static _brokenDownDateToMillisecondsSinceEpoch( | 193 /* patch */ static int _brokenDownDateToMillisecondsSinceEpoch( |
194 int year, int month, int day, | 194 int year, int month, int day, |
195 int hour, int minute, int second, int millisecond, | 195 int hour, int minute, int second, int millisecond, |
196 bool isUtc) { | 196 bool isUtc) { |
197 // Simplify calculations by working with zero-based month. | 197 // Simplify calculations by working with zero-based month. |
198 --month; | 198 --month; |
199 // Deal with under and overflow. | 199 // Deal with under and overflow. |
200 year += (month / 12).floor(); | 200 year += (month / 12).floor(); |
201 month = month % 12; | 201 month = month % 12; |
202 | 202 |
203 // First compute the seconds in UTC, independent of the [isUtc] flag. If | 203 // First compute the seconds in UTC, independent of the [isUtc] flag. If |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 } | 242 } |
243 | 243 |
244 /** | 244 /** |
245 * Returns a year in the range 2008-2035 matching | 245 * Returns a year in the range 2008-2035 matching |
246 * * leap year, and | 246 * * leap year, and |
247 * * week day of first day. | 247 * * week day of first day. |
248 * | 248 * |
249 * Leap seconds are ignored. | 249 * Leap seconds are ignored. |
250 * Adapted from V8's date implementation. See ECMA 262 - 15.9.1.9. | 250 * Adapted from V8's date implementation. See ECMA 262 - 15.9.1.9. |
251 */ | 251 */ |
252 static _equivalentYear(int year) { | 252 static int _equivalentYear(int year) { |
253 // Returns the week day (in range 0 - 6). | 253 // Returns the week day (in range 0 - 6). |
254 // 1/1/1956 was a Sunday (i.e. weekday 0). 1956 was a leap-year. | 254 // 1/1/1956 was a Sunday (i.e. weekday 0). 1956 was a leap-year. |
255 // 1/1/1967 was a Sunday (i.e. weekday 0). | 255 // 1/1/1967 was a Sunday (i.e. weekday 0). |
256 // Without leap years a subsequent year has a week day + 1 (for example | 256 // Without leap years a subsequent year has a week day + 1 (for example |
257 // 1/1/1968 was a Monday). With leap-years it jumps over one week day | 257 // 1/1/1968 was a Monday). With leap-years it jumps over one week day |
258 // (e.g. 1/1/1957 was a Tuesday). | 258 // (e.g. 1/1/1957 was a Tuesday). |
259 // After 12 years the weekdays have advanced by 12 days + 3 leap days = | 259 // After 12 years the weekdays have advanced by 12 days + 3 leap days = |
260 // 15 days. 15 % 7 = 1. So after 12 years the week day has always | 260 // 15 days. 15 % 7 = 1. So after 12 years the week day has always |
261 // (now independently of leap-years) advanced by one. | 261 // (now independently of leap-years) advanced by one. |
262 // weekDay * 12 gives thus a year starting with the wanted weekDay. | 262 // weekDay * 12 gives thus a year starting with the wanted weekDay. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 static int _timeZoneOffsetInSeconds(int millisecondsSinceEpoch) { | 317 static int _timeZoneOffsetInSeconds(int millisecondsSinceEpoch) { |
318 int equivalentSeconds = _equivalentSeconds(millisecondsSinceEpoch); | 318 int equivalentSeconds = _equivalentSeconds(millisecondsSinceEpoch); |
319 return _timeZoneOffsetInSecondsForClampedSeconds(equivalentSeconds); | 319 return _timeZoneOffsetInSecondsForClampedSeconds(equivalentSeconds); |
320 } | 320 } |
321 | 321 |
322 static String _timeZoneName(int millisecondsSinceEpoch) { | 322 static String _timeZoneName(int millisecondsSinceEpoch) { |
323 int equivalentSeconds = _equivalentSeconds(millisecondsSinceEpoch); | 323 int equivalentSeconds = _equivalentSeconds(millisecondsSinceEpoch); |
324 return _timeZoneNameForClampedSeconds(equivalentSeconds); | 324 return _timeZoneNameForClampedSeconds(equivalentSeconds); |
325 } | 325 } |
326 } | 326 } |
OLD | NEW |