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

Unified Diff: runtime/lib/date_patch.dart

Issue 10832166: 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: rebase Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/compiler/implementation/lib/js_helper.dart ('k') | tests/co19/co19-compiler.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/date_patch.dart
diff --git a/runtime/lib/date_patch.dart b/runtime/lib/date_patch.dart
index 247dddd10611c1aec588d642df244fff89586e57..d5002553e8ca010ee8c8662cc67c0c8163560842 100644
--- a/runtime/lib/date_patch.dart
+++ b/runtime/lib/date_patch.dart
@@ -5,7 +5,7 @@
// VM implementation of DateImplementation.
patch class DateImplementation {
- /* patch */ DateImplementation(int years,
+ /* patch */ DateImplementation(int year,
[int month = 1,
int day = 1,
int hour = 0,
@@ -15,7 +15,7 @@ patch class DateImplementation {
bool isUtc = false])
: this.isUtc = isUtc,
this.millisecondsSinceEpoch = _brokenDownDateToMillisecondsSinceEpoch(
- years, month, day, hour, minute, second, millisecond, isUtc) {
+ year, month, day, hour, minute, second, millisecond, isUtc) {
if (millisecondsSinceEpoch === null) throw new IllegalArgumentException();
if (isUtc === null) throw new IllegalArgumentException();
}
@@ -177,23 +177,20 @@ patch class DateImplementation {
}
static _brokenDownDateToMillisecondsSinceEpoch(
- int years, int month, int day,
+ int year, int month, int day,
int hour, int minute, int second, int millisecond,
bool isUtc) {
- if ((month < 1) || (month > 12)) return null;
- if ((day < 1) || (day > 31)) return null;
- // Leap seconds can lead to hour == 24.
- if ((hour < 0) || (hour > 24)) return null;
- if ((hour == 24) && ((minute != 0) || (second != 0))) return null;
- if ((minute < 0) || (minute > 59)) return null;
- if ((second < 0) || (second > 59)) return null;
- if ((millisecond < 0) || (millisecond > 999)) return null;
+ // Simplify calculations by working with zero-based month.
+ --month;
+ // Deal with under and overflow.
+ year += (month / 12).floor().toInt();
+ month = month % 12;
// First compute the seconds in UTC, independent of the [isUtc] flag. If
// necessary we will add the time-zone offset later on.
int days = day - 1;
- days += _DAYS_UNTIL_MONTH[_isLeapYear(years) ? 1 : 0][month - 1];
- days += _dayFromYear(years);
+ days += _DAYS_UNTIL_MONTH[_isLeapYear(year) ? 1 : 0][month];
+ days += _dayFromYear(year);
int millisecondsSinceEpoch = days * Duration.MILLISECONDS_PER_DAY +
hour * Duration.MILLISECONDS_PER_HOUR +
minute * Duration.MILLISECONDS_PER_MINUTE+
« no previous file with comments | « lib/compiler/implementation/lib/js_helper.dart ('k') | tests/co19/co19-compiler.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698