Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: runtime/lib/date_patch.dart

Issue 2759973004: Fix observatory tests broken by running dartfmt. Temporarily reverted formatting for evaluate_activ… (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/lib/core_patch.dart ('k') | runtime/lib/deferred_load_patch.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
8 class DateTime {
8 // Natives. 9 // Natives.
9 // The natives have been moved up here to work around Issue 10401. 10 // The natives have been moved up here to work around Issue 10401.
10 static int _getCurrentMicros() native "DateTime_currentTimeMicros"; 11 static int _getCurrentMicros() native "DateTime_currentTimeMicros";
11 12
12 static String _timeZoneNameForClampedSeconds(int secondsSinceEpoch) 13 static String _timeZoneNameForClampedSeconds(int secondsSinceEpoch)
13 native "DateTime_timeZoneName"; 14 native "DateTime_timeZoneName";
14 15
15 static int _timeZoneOffsetInSecondsForClampedSeconds(int secondsSinceEpoch) 16 static int _timeZoneOffsetInSecondsForClampedSeconds(int secondsSinceEpoch)
16 native "DateTime_timeZoneOffsetInSeconds"; 17 native "DateTime_timeZoneOffsetInSeconds";
17 18
18 static int _localTimeZoneAdjustmentInSeconds() 19 static int _localTimeZoneAdjustmentInSeconds()
19 native "DateTime_localTimeZoneAdjustmentInSeconds"; 20 native "DateTime_localTimeZoneAdjustmentInSeconds";
20 21
21 static const _MICROSECOND_INDEX = 0; 22 static const _MICROSECOND_INDEX = 0;
22 static const _MILLISECOND_INDEX = 1; 23 static const _MILLISECOND_INDEX = 1;
23 static const _SECOND_INDEX = 2; 24 static const _SECOND_INDEX = 2;
24 static const _MINUTE_INDEX = 3; 25 static const _MINUTE_INDEX = 3;
25 static const _HOUR_INDEX = 4; 26 static const _HOUR_INDEX = 4;
26 static const _DAY_INDEX = 5; 27 static const _DAY_INDEX = 5;
27 static const _WEEKDAY_INDEX = 6; 28 static const _WEEKDAY_INDEX = 6;
28 static const _MONTH_INDEX = 7; 29 static const _MONTH_INDEX = 7;
29 static const _YEAR_INDEX = 8; 30 static const _YEAR_INDEX = 8;
30 31
31 List __parts; 32 List __parts;
32 33
33 @patch DateTime.fromMillisecondsSinceEpoch(int millisecondsSinceEpoch, 34 @patch
34 {bool isUtc: false}) 35 DateTime.fromMillisecondsSinceEpoch(int millisecondsSinceEpoch,
36 {bool isUtc: false})
35 : this._withValue( 37 : this._withValue(
36 millisecondsSinceEpoch * Duration.MICROSECONDS_PER_MILLISECOND, 38 millisecondsSinceEpoch * Duration.MICROSECONDS_PER_MILLISECOND,
37 isUtc: isUtc); 39 isUtc: isUtc);
38 40
39 @patch DateTime.fromMicrosecondsSinceEpoch(int microsecondsSinceEpoch, 41 @patch
40 {bool isUtc: false}) 42 DateTime.fromMicrosecondsSinceEpoch(int microsecondsSinceEpoch,
43 {bool isUtc: false})
41 : this._withValue(microsecondsSinceEpoch, isUtc: isUtc); 44 : this._withValue(microsecondsSinceEpoch, isUtc: isUtc);
42 45
43 @patch DateTime._internal(int year, 46 @patch
44 int month, 47 DateTime._internal(int year, int month, int day, int hour, int minute,
45 int day, 48 int second, int millisecond, int microsecond, bool isUtc)
46 int hour,
47 int minute,
48 int second,
49 int millisecond,
50 int microsecond,
51 bool isUtc)
52 : this.isUtc = isUtc, 49 : this.isUtc = isUtc,
53 this._value = _brokenDownDateToValue( 50 this._value = _brokenDownDateToValue(year, month, day, hour, minute,
54 year, month, day, hour, minute, second, millisecond, microsecond, 51 second, millisecond, microsecond, isUtc) {
55 isUtc) {
56 if (_value == null) throw new ArgumentError(); 52 if (_value == null) throw new ArgumentError();
57 if (isUtc == null) throw new ArgumentError(); 53 if (isUtc == null) throw new ArgumentError();
58 } 54 }
59 55
60 @patch DateTime._now() 56 @patch
57 DateTime._now()
61 : isUtc = false, 58 : isUtc = false,
62 _value = _getCurrentMicros() { 59 _value = _getCurrentMicros() {}
63 }
64 60
65 @patch String get timeZoneName { 61 @patch
62 String get timeZoneName {
66 if (isUtc) return "UTC"; 63 if (isUtc) return "UTC";
67 return _timeZoneName(microsecondsSinceEpoch); 64 return _timeZoneName(microsecondsSinceEpoch);
68 } 65 }
69 66
70 @patch Duration get timeZoneOffset { 67 @patch
68 Duration get timeZoneOffset {
71 if (isUtc) return new Duration(); 69 if (isUtc) return new Duration();
72 int offsetInSeconds = _timeZoneOffsetInSeconds(microsecondsSinceEpoch); 70 int offsetInSeconds = _timeZoneOffsetInSeconds(microsecondsSinceEpoch);
73 return new Duration(seconds: offsetInSeconds); 71 return new Duration(seconds: offsetInSeconds);
74 } 72 }
75 73
76 /** The first list contains the days until each month in non-leap years. The 74 /** The first list contains the days until each month in non-leap years. The
77 * second list contains the days in leap years. */ 75 * second list contains the days in leap years. */
78 static const List<List<int>> _DAYS_UNTIL_MONTH = 76 static const List<List<int>> _DAYS_UNTIL_MONTH = const [
79 const [const [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334], 77 const [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334],
80 const [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335]]; 78 const [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335]
79 ];
81 80
82 static List _computeUpperPart(int localMicros) { 81 static List _computeUpperPart(int localMicros) {
83 const int DAYS_IN_4_YEARS = 4 * 365 + 1; 82 const int DAYS_IN_4_YEARS = 4 * 365 + 1;
84 const int DAYS_IN_100_YEARS = 25 * DAYS_IN_4_YEARS - 1; 83 const int DAYS_IN_100_YEARS = 25 * DAYS_IN_4_YEARS - 1;
85 const int DAYS_IN_400_YEARS = 4 * DAYS_IN_100_YEARS + 1; 84 const int DAYS_IN_400_YEARS = 4 * DAYS_IN_100_YEARS + 1;
86 const int DAYS_1970_TO_2000 = 30 * 365 + 7; 85 const int DAYS_1970_TO_2000 = 30 * 365 + 7;
87 const int DAYS_OFFSET = 1000 * DAYS_IN_400_YEARS + 5 * DAYS_IN_400_YEARS - 86 const int DAYS_OFFSET =
88 DAYS_1970_TO_2000; 87 1000 * DAYS_IN_400_YEARS + 5 * DAYS_IN_400_YEARS - DAYS_1970_TO_2000;
89 const int YEARS_OFFSET = 400000; 88 const int YEARS_OFFSET = 400000;
90 89
91 int resultYear = 0; 90 int resultYear = 0;
92 int resultMonth = 0; 91 int resultMonth = 0;
93 int resultDay = 0; 92 int resultDay = 0;
94 93
95 // Always round down. 94 // Always round down.
96 final int daysSince1970 = _flooredDivision(localMicros, 95 final int daysSince1970 =
97 Duration.MICROSECONDS_PER_DAY); 96 _flooredDivision(localMicros, Duration.MICROSECONDS_PER_DAY);
98 int days = daysSince1970; 97 int days = daysSince1970;
99 days += DAYS_OFFSET; 98 days += DAYS_OFFSET;
100 resultYear = 400 * (days ~/ DAYS_IN_400_YEARS) - YEARS_OFFSET; 99 resultYear = 400 * (days ~/ DAYS_IN_400_YEARS) - YEARS_OFFSET;
101 days = days.remainder(DAYS_IN_400_YEARS); 100 days = days.remainder(DAYS_IN_400_YEARS);
102 days--; 101 days--;
103 int yd1 = days ~/ DAYS_IN_100_YEARS; 102 int yd1 = days ~/ DAYS_IN_100_YEARS;
104 days = days.remainder(DAYS_IN_100_YEARS); 103 days = days.remainder(DAYS_IN_100_YEARS);
105 resultYear += 100 * yd1; 104 resultYear += 100 * yd1;
106 days++; 105 days++;
107 int yd2 = days ~/ DAYS_IN_4_YEARS; 106 int yd2 = days ~/ DAYS_IN_4_YEARS;
108 days = days.remainder(DAYS_IN_4_YEARS); 107 days = days.remainder(DAYS_IN_4_YEARS);
109 resultYear += 4 * yd2; 108 resultYear += 4 * yd2;
110 days--; 109 days--;
111 int yd3 = days ~/ 365; 110 int yd3 = days ~/ 365;
112 days = days.remainder(365); 111 days = days.remainder(365);
113 resultYear += yd3; 112 resultYear += yd3;
114 113
115 bool isLeap = (yd1 == 0 || yd2 != 0) && yd3 == 0; 114 bool isLeap = (yd1 == 0 || yd2 != 0) && yd3 == 0;
116 if (isLeap) days++; 115 if (isLeap) days++;
117 116
118 List<int> daysUntilMonth = _DAYS_UNTIL_MONTH[isLeap ? 1 : 0]; 117 List<int> daysUntilMonth = _DAYS_UNTIL_MONTH[isLeap ? 1 : 0];
119 for (resultMonth = 12; 118 for (resultMonth = 12;
120 daysUntilMonth[resultMonth - 1] > days; 119 daysUntilMonth[resultMonth - 1] > days;
121 resultMonth--) { 120 resultMonth--) {
122 // Do nothing. 121 // Do nothing.
123 } 122 }
124 resultDay = days - daysUntilMonth[resultMonth - 1] + 1; 123 resultDay = days - daysUntilMonth[resultMonth - 1] + 1;
125 124
126 int resultMicrosecond = localMicros % Duration.MICROSECONDS_PER_MILLISECOND; 125 int resultMicrosecond = localMicros % Duration.MICROSECONDS_PER_MILLISECOND;
127 int resultMillisecond = 126 int resultMillisecond =
128 _flooredDivision(localMicros, Duration.MICROSECONDS_PER_MILLISECOND) % 127 _flooredDivision(localMicros, Duration.MICROSECONDS_PER_MILLISECOND) %
129 Duration.MILLISECONDS_PER_SECOND; 128 Duration.MILLISECONDS_PER_SECOND;
130 int resultSecond = 129 int resultSecond =
131 _flooredDivision(localMicros, Duration.MICROSECONDS_PER_SECOND) % 130 _flooredDivision(localMicros, Duration.MICROSECONDS_PER_SECOND) %
132 Duration.SECONDS_PER_MINUTE; 131 Duration.SECONDS_PER_MINUTE;
133 132
134 int resultMinute = _flooredDivision(localMicros, 133 int resultMinute =
135 Duration.MICROSECONDS_PER_MINUTE); 134 _flooredDivision(localMicros, Duration.MICROSECONDS_PER_MINUTE);
136 resultMinute %= Duration.MINUTES_PER_HOUR; 135 resultMinute %= Duration.MINUTES_PER_HOUR;
137 136
138 int resultHour = 137 int resultHour =
139 _flooredDivision(localMicros, Duration.MICROSECONDS_PER_HOUR); 138 _flooredDivision(localMicros, Duration.MICROSECONDS_PER_HOUR);
140 resultHour %= Duration.HOURS_PER_DAY; 139 resultHour %= Duration.HOURS_PER_DAY;
141 140
142 // In accordance with ISO 8601 a week 141 // In accordance with ISO 8601 a week
143 // starts with Monday. Monday has the value 1 up to Sunday with 7. 142 // starts with Monday. Monday has the value 1 up to Sunday with 7.
144 // 1970-1-1 was a Thursday. 143 // 1970-1-1 was a Thursday.
145 int resultWeekday = ((daysSince1970 + DateTime.THURSDAY - DateTime.MONDAY) % 144 int resultWeekday = ((daysSince1970 + DateTime.THURSDAY - DateTime.MONDAY) %
146 DateTime.DAYS_PER_WEEK) + DateTime.MONDAY; 145 DateTime.DAYS_PER_WEEK) +
146 DateTime.MONDAY;
147 147
148 List list = new List(_YEAR_INDEX + 1); 148 List list = new List(_YEAR_INDEX + 1);
149 list[_MICROSECOND_INDEX] = resultMicrosecond; 149 list[_MICROSECOND_INDEX] = resultMicrosecond;
150 list[_MILLISECOND_INDEX] = resultMillisecond; 150 list[_MILLISECOND_INDEX] = resultMillisecond;
151 list[_SECOND_INDEX] = resultSecond; 151 list[_SECOND_INDEX] = resultSecond;
152 list[_MINUTE_INDEX] = resultMinute; 152 list[_MINUTE_INDEX] = resultMinute;
153 list[_HOUR_INDEX] = resultHour; 153 list[_HOUR_INDEX] = resultHour;
154 list[_DAY_INDEX] = resultDay; 154 list[_DAY_INDEX] = resultDay;
155 list[_WEEKDAY_INDEX] = resultWeekday; 155 list[_WEEKDAY_INDEX] = resultWeekday;
156 list[_MONTH_INDEX] = resultMonth; 156 list[_MONTH_INDEX] = resultMonth;
157 list[_YEAR_INDEX] = resultYear; 157 list[_YEAR_INDEX] = resultYear;
158 return list; 158 return list;
159 } 159 }
160 160
161 get _parts { 161 get _parts {
162 if (__parts == null) { 162 if (__parts == null) {
163 __parts = _computeUpperPart(_localDateInUtcMicros); 163 __parts = _computeUpperPart(_localDateInUtcMicros);
164 } 164 }
165 return __parts; 165 return __parts;
166 } 166 }
167 167
168 @patch DateTime add(Duration duration) { 168 @patch
169 return new DateTime._withValue( 169 DateTime add(Duration duration) {
170 _value + duration.inMicroseconds, isUtc: isUtc); 170 return new DateTime._withValue(_value + duration.inMicroseconds,
171 isUtc: isUtc);
171 } 172 }
172 173
173 @patch DateTime subtract(Duration duration) { 174 @patch
174 return new DateTime._withValue( 175 DateTime subtract(Duration duration) {
175 _value - duration.inMicroseconds, isUtc: isUtc); 176 return new DateTime._withValue(_value - duration.inMicroseconds,
177 isUtc: isUtc);
176 } 178 }
177 179
178 @patch Duration difference(DateTime other) { 180 @patch
181 Duration difference(DateTime other) {
179 return new Duration(microseconds: _value - other._value); 182 return new Duration(microseconds: _value - other._value);
180 } 183 }
181 184
182 @patch int get millisecondsSinceEpoch => 185 @patch
186 int get millisecondsSinceEpoch =>
183 _value ~/ Duration.MICROSECONDS_PER_MILLISECOND; 187 _value ~/ Duration.MICROSECONDS_PER_MILLISECOND;
184 188
185 @patch int get microsecondsSinceEpoch => _value; 189 @patch
190 int get microsecondsSinceEpoch => _value;
186 191
187 @patch int get microsecond => _parts[_MICROSECOND_INDEX]; 192 @patch
193 int get microsecond => _parts[_MICROSECOND_INDEX];
188 194
189 @patch int get millisecond => _parts[_MILLISECOND_INDEX]; 195 @patch
196 int get millisecond => _parts[_MILLISECOND_INDEX];
190 197
191 @patch int get second => _parts[_SECOND_INDEX]; 198 @patch
199 int get second => _parts[_SECOND_INDEX];
192 200
193 @patch int get minute => _parts[_MINUTE_INDEX]; 201 @patch
202 int get minute => _parts[_MINUTE_INDEX];
194 203
195 @patch int get hour => _parts[_HOUR_INDEX]; 204 @patch
205 int get hour => _parts[_HOUR_INDEX];
196 206
197 @patch int get day => _parts[_DAY_INDEX]; 207 @patch
208 int get day => _parts[_DAY_INDEX];
198 209
199 @patch int get weekday => _parts[_WEEKDAY_INDEX]; 210 @patch
211 int get weekday => _parts[_WEEKDAY_INDEX];
200 212
201 @patch int get month => _parts[_MONTH_INDEX]; 213 @patch
214 int get month => _parts[_MONTH_INDEX];
202 215
203 @patch int get year => _parts[_YEAR_INDEX]; 216 @patch
217 int get year => _parts[_YEAR_INDEX];
204 218
205 /** 219 /**
206 * Returns the amount of microseconds in UTC that represent the same values 220 * Returns the amount of microseconds in UTC that represent the same values
207 * as [this]. 221 * as [this].
208 * 222 *
209 * Say `t` is the result of this function, then 223 * Say `t` is the result of this function, then
210 * * `this.year == new DateTime.fromMicrosecondsSinceEpoch(t, true).year`, 224 * * `this.year == new DateTime.fromMicrosecondsSinceEpoch(t, true).year`,
211 * * `this.month == new DateTime.fromMicrosecondsSinceEpoch(t, true).month`, 225 * * `this.month == new DateTime.fromMicrosecondsSinceEpoch(t, true).month`,
212 * * `this.day == new DateTime.fromMicrosecondsSinceEpoch(t, true).day`, 226 * * `this.day == new DateTime.fromMicrosecondsSinceEpoch(t, true).day`,
213 * * `this.hour == new DateTime.fromMicrosecondsSinceEpoch(t, true).hour`, 227 * * `this.hour == new DateTime.fromMicrosecondsSinceEpoch(t, true).hour`,
(...skipping 11 matching lines...) Expand all
225 return micros + offset; 239 return micros + offset;
226 } 240 }
227 241
228 static int _flooredDivision(int a, int b) { 242 static int _flooredDivision(int a, int b) {
229 return (a - (a < 0 ? b - 1 : 0)) ~/ b; 243 return (a - (a < 0 ? b - 1 : 0)) ~/ b;
230 } 244 }
231 245
232 // Returns the days since 1970 for the start of the given [year]. 246 // Returns the days since 1970 for the start of the given [year].
233 // [year] may be before epoch. 247 // [year] may be before epoch.
234 static int _dayFromYear(int year) { 248 static int _dayFromYear(int year) {
235 return 365 * (year - 1970) 249 return 365 * (year - 1970) +
236 + _flooredDivision(year - 1969, 4) 250 _flooredDivision(year - 1969, 4) -
237 - _flooredDivision(year - 1901, 100) 251 _flooredDivision(year - 1901, 100) +
238 + _flooredDivision(year - 1601, 400); 252 _flooredDivision(year - 1601, 400);
239 } 253 }
240 254
241 static bool _isLeapYear(y) { 255 static bool _isLeapYear(y) {
242 // (y % 16 == 0) matches multiples of 400, and is faster than % 400. 256 // (y % 16 == 0) matches multiples of 400, and is faster than % 400.
243 return (y % 4 == 0) && ((y % 16 == 0) || (y % 100 != 0)); 257 return (y % 4 == 0) && ((y % 16 == 0) || (y % 100 != 0));
244 } 258 }
245 259
246 /// Converts the given broken down date to microseconds. 260 /// Converts the given broken down date to microseconds.
247 @patch static int _brokenDownDateToValue( 261 @patch
248 int year, int month, int day, 262 static int _brokenDownDateToValue(int year, int month, int day, int hour,
249 int hour, int minute, int second, int millisecond, int microsecond, 263 int minute, int second, int millisecond, int microsecond, bool isUtc) {
250 bool isUtc) {
251 // Simplify calculations by working with zero-based month. 264 // Simplify calculations by working with zero-based month.
252 --month; 265 --month;
253 // Deal with under and overflow. 266 // Deal with under and overflow.
254 if (month >= 12) { 267 if (month >= 12) {
255 year += month ~/ 12; 268 year += month ~/ 12;
256 month = month % 12; 269 month = month % 12;
257 } else if (month < 0) { 270 } else if (month < 0) {
258 int realMonth = month % 12; 271 int realMonth = month % 12;
259 year += (month - realMonth) ~/ 12; 272 year += (month - realMonth) ~/ 12;
260 month = realMonth; 273 month = realMonth;
261 } 274 }
262 275
263 // First compute the seconds in UTC, independent of the [isUtc] flag. If 276 // First compute the seconds in UTC, independent of the [isUtc] flag. If
264 // necessary we will add the time-zone offset later on. 277 // necessary we will add the time-zone offset later on.
265 int days = day - 1; 278 int days = day - 1;
266 days += _DAYS_UNTIL_MONTH[_isLeapYear(year) ? 1 : 0][month]; 279 days += _DAYS_UNTIL_MONTH[_isLeapYear(year) ? 1 : 0][month];
267 days += _dayFromYear(year); 280 days += _dayFromYear(year);
268 int microsecondsSinceEpoch = 281 int microsecondsSinceEpoch = days * Duration.MICROSECONDS_PER_DAY +
269 days * Duration.MICROSECONDS_PER_DAY + 282 hour * Duration.MICROSECONDS_PER_HOUR +
270 hour * Duration.MICROSECONDS_PER_HOUR +
271 minute * Duration.MICROSECONDS_PER_MINUTE + 283 minute * Duration.MICROSECONDS_PER_MINUTE +
272 second * Duration.MICROSECONDS_PER_SECOND + 284 second * Duration.MICROSECONDS_PER_SECOND +
273 millisecond * Duration.MICROSECONDS_PER_MILLISECOND + 285 millisecond * Duration.MICROSECONDS_PER_MILLISECOND +
274 microsecond; 286 microsecond;
275 287
276 // Since [_timeZoneOffsetInSeconds] will crash if the input is far out of 288 // Since [_timeZoneOffsetInSeconds] will crash if the input is far out of
277 // the valid range we do a preliminary test that weeds out values that can 289 // the valid range we do a preliminary test that weeds out values that can
278 // not become valid even with timezone adjustments. 290 // not become valid even with timezone adjustments.
279 // The timezone adjustment is always less than a day, so adding a security 291 // The timezone adjustment is always less than a day, so adding a security
280 // margin of one day should be enough. 292 // margin of one day should be enough.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 * 382 *
371 * * The time since the beginning of the year is the same. 383 * * The time since the beginning of the year is the same.
372 * * If the given date is in a leap year then the returned 384 * * If the given date is in a leap year then the returned
373 * seconds are in a leap year, too. 385 * seconds are in a leap year, too.
374 * * The week day of given date is the same as the one for the 386 * * The week day of given date is the same as the one for the
375 * returned date. 387 * returned date.
376 */ 388 */
377 static int _equivalentSeconds(int microsecondsSinceEpoch) { 389 static int _equivalentSeconds(int microsecondsSinceEpoch) {
378 const int CUT_OFF_SECONDS = 0x7FFFFFFF; 390 const int CUT_OFF_SECONDS = 0x7FFFFFFF;
379 391
380 int secondsSinceEpoch = _flooredDivision(microsecondsSinceEpoch, 392 int secondsSinceEpoch = _flooredDivision(
381 Duration.MICROSECONDS_PER_SECOND); 393 microsecondsSinceEpoch, Duration.MICROSECONDS_PER_SECOND);
382 394
383 if (secondsSinceEpoch.abs() > CUT_OFF_SECONDS) { 395 if (secondsSinceEpoch.abs() > CUT_OFF_SECONDS) {
384 int year = _yearsFromSecondsSinceEpoch(secondsSinceEpoch); 396 int year = _yearsFromSecondsSinceEpoch(secondsSinceEpoch);
385 int days = _dayFromYear(year); 397 int days = _dayFromYear(year);
386 int equivalentYear = _equivalentYear(year); 398 int equivalentYear = _equivalentYear(year);
387 int equivalentDays = _dayFromYear(equivalentYear); 399 int equivalentDays = _dayFromYear(equivalentYear);
388 int diffDays = equivalentDays - days; 400 int diffDays = equivalentDays - days;
389 secondsSinceEpoch += diffDays * Duration.SECONDS_PER_DAY; 401 secondsSinceEpoch += diffDays * Duration.SECONDS_PER_DAY;
390 } 402 }
391 return secondsSinceEpoch; 403 return secondsSinceEpoch;
392 } 404 }
393 405
394 static int _timeZoneOffsetInSeconds(int microsecondsSinceEpoch) { 406 static int _timeZoneOffsetInSeconds(int microsecondsSinceEpoch) {
395 int equivalentSeconds = _equivalentSeconds(microsecondsSinceEpoch); 407 int equivalentSeconds = _equivalentSeconds(microsecondsSinceEpoch);
396 return _timeZoneOffsetInSecondsForClampedSeconds(equivalentSeconds); 408 return _timeZoneOffsetInSecondsForClampedSeconds(equivalentSeconds);
397 } 409 }
398 410
399 static String _timeZoneName(int microsecondsSinceEpoch) { 411 static String _timeZoneName(int microsecondsSinceEpoch) {
400 int equivalentSeconds = _equivalentSeconds(microsecondsSinceEpoch); 412 int equivalentSeconds = _equivalentSeconds(microsecondsSinceEpoch);
401 return _timeZoneNameForClampedSeconds(equivalentSeconds); 413 return _timeZoneNameForClampedSeconds(equivalentSeconds);
402 } 414 }
403 } 415 }
OLDNEW
« no previous file with comments | « runtime/lib/core_patch.dart ('k') | runtime/lib/deferred_load_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698