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

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

Issue 10894009: Revert "Updated VM and JS versions of Date to allow underflow and overflow." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « lib/compiler/implementation/lib/js_helper.dart ('k') | tests/corelib/date_time_test.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 DateImplementation. 6 // VM implementation of DateImplementation.
7 patch class DateImplementation { 7 patch class DateImplementation {
8 /* patch */ DateImplementation(int year, 8 /* patch */ DateImplementation(int years,
9 [int month = 1, 9 [int month = 1,
10 int day = 1, 10 int day = 1,
11 int hour = 0, 11 int hour = 0,
12 int minute = 0, 12 int minute = 0,
13 int second = 0, 13 int second = 0,
14 int millisecond = 0, 14 int millisecond = 0,
15 bool isUtc = false]) 15 bool isUtc = false])
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 years, month, day, hour, minute, second, millisecond, isUtc) {
19 if (millisecondsSinceEpoch === null) throw new IllegalArgumentException(); 19 if (millisecondsSinceEpoch === null) throw new IllegalArgumentException();
20 if (isUtc === null) throw new IllegalArgumentException(); 20 if (isUtc === null) throw new IllegalArgumentException();
21 } 21 }
22 22
23 /* patch */ DateImplementation.now() 23 /* patch */ DateImplementation.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() {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 - _flooredDivision(year - 1901, 100) 170 - _flooredDivision(year - 1901, 100)
171 + _flooredDivision(year - 1601, 400); 171 + _flooredDivision(year - 1601, 400);
172 } 172 }
173 173
174 static bool _isLeapYear(y) { 174 static bool _isLeapYear(y) {
175 return (y.remainder(4) == 0) && 175 return (y.remainder(4) == 0) &&
176 ((y.remainder(100) != 0) || (y.remainder(400) == 0)); 176 ((y.remainder(100) != 0) || (y.remainder(400) == 0));
177 } 177 }
178 178
179 static _brokenDownDateToMillisecondsSinceEpoch( 179 static _brokenDownDateToMillisecondsSinceEpoch(
180 int year, int month, int day, 180 int years, int month, int day,
181 int hour, int minute, int second, int millisecond, 181 int hour, int minute, int second, int millisecond,
182 bool isUtc) { 182 bool isUtc) {
183 // Simplify calculations by working with zero-based month. 183 if ((month < 1) || (month > 12)) return null;
184 --month; 184 if ((day < 1) || (day > 31)) return null;
185 // Deal with under and overflow. 185 // Leap seconds can lead to hour == 24.
186 year += (month / 12).floor().toInt(); 186 if ((hour < 0) || (hour > 24)) return null;
187 month = month % 12; 187 if ((hour == 24) && ((minute != 0) || (second != 0))) return null;
188 if ((minute < 0) || (minute > 59)) return null;
189 if ((second < 0) || (second > 59)) return null;
190 if ((millisecond < 0) || (millisecond > 999)) return null;
188 191
189 // First compute the seconds in UTC, independent of the [isUtc] flag. If 192 // First compute the seconds in UTC, independent of the [isUtc] flag. If
190 // necessary we will add the time-zone offset later on. 193 // necessary we will add the time-zone offset later on.
191 int days = day - 1; 194 int days = day - 1;
192 days += _DAYS_UNTIL_MONTH[_isLeapYear(year) ? 1 : 0][month]; 195 days += _DAYS_UNTIL_MONTH[_isLeapYear(years) ? 1 : 0][month - 1];
193 days += _dayFromYear(year); 196 days += _dayFromYear(years);
194 int millisecondsSinceEpoch = days * Duration.MILLISECONDS_PER_DAY + 197 int millisecondsSinceEpoch = days * Duration.MILLISECONDS_PER_DAY +
195 hour * Duration.MILLISECONDS_PER_HOUR + 198 hour * Duration.MILLISECONDS_PER_HOUR +
196 minute * Duration.MILLISECONDS_PER_MINUTE+ 199 minute * Duration.MILLISECONDS_PER_MINUTE+
197 second * Duration.MILLISECONDS_PER_SECOND + 200 second * Duration.MILLISECONDS_PER_SECOND +
198 millisecond; 201 millisecond;
199 202
200 // Since [_timeZoneOffsetInSeconds] will crash if the input is far out of 203 // Since [_timeZoneOffsetInSeconds] will crash if the input is far out of
201 // the valid range we do a preliminary test that weeds out values that can 204 // the valid range we do a preliminary test that weeds out values that can
202 // not become valid even with timezone adjustments. 205 // not become valid even with timezone adjustments.
203 // The timezone adjustment is always less than a day, so adding a security 206 // The timezone adjustment is always less than a day, so adding a security
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 318
316 static String _timeZoneNameForClampedSeconds(int secondsSinceEpoch) 319 static String _timeZoneNameForClampedSeconds(int secondsSinceEpoch)
317 native "DateNatives_timeZoneName"; 320 native "DateNatives_timeZoneName";
318 321
319 static int _timeZoneOffsetInSecondsForClampedSeconds(int secondsSinceEpoch) 322 static int _timeZoneOffsetInSecondsForClampedSeconds(int secondsSinceEpoch)
320 native "DateNatives_timeZoneOffsetInSeconds"; 323 native "DateNatives_timeZoneOffsetInSeconds";
321 324
322 static int _localTimeZoneAdjustmentInSeconds() 325 static int _localTimeZoneAdjustmentInSeconds()
323 native "DateNatives_localTimeZoneAdjustmentInSeconds"; 326 native "DateNatives_localTimeZoneAdjustmentInSeconds";
324 } 327 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/lib/js_helper.dart ('k') | tests/corelib/date_time_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698