Index: src/runtime.cc |
=================================================================== |
--- src/runtime.cc (revision 4103) |
+++ src/runtime.cc (working copy) |
@@ -5076,14 +5076,7 @@ |
} |
-static Object* Runtime_DateMakeDay(Arguments args) { |
- NoHandleAllocation ha; |
- ASSERT(args.length() == 3); |
- |
- CONVERT_SMI_CHECKED(year, args[0]); |
- CONVERT_SMI_CHECKED(month, args[1]); |
- CONVERT_SMI_CHECKED(date, args[2]); |
- |
+static int MakeDay(int year, int month, int day) { |
static const int day_from_month[] = {0, 31, 59, 90, 120, 151, |
Mads Ager (chromium)
2010/03/12 08:00:21
Let's change these constants to follow the Google
|
181, 212, 243, 273, 304, 334}; |
static const int day_from_month_leap[] = {0, 31, 60, 91, 121, 152, |
@@ -5105,7 +5098,7 @@ |
// ECMA 262 - 15.9.1.1, i.e. upto 100,000,000 days on either side of |
// Jan 1 1970. This is required so that we don't run into integer |
// division of negative numbers. |
- // c) there shouldn't be overflow for 32-bit integers in the following |
+ // c) there shouldn't be an overflow for 32-bit integers in the following |
// operations. |
static const int year_delta = 399999; |
static const int base_day = 365 * (1970 + year_delta) + |
@@ -5121,13 +5114,330 @@ |
base_day; |
if (year % 4 || (year % 100 == 0 && year % 400 != 0)) { |
- return Smi::FromInt(day_from_year + day_from_month[month] + date - 1); |
+ return day_from_year + day_from_month[month] + day - 1; |
} |
- return Smi::FromInt(day_from_year + day_from_month_leap[month] + date - 1); |
+ return day_from_year + day_from_month_leap[month] + day - 1; |
} |
+static Object* Runtime_DateMakeDay(Arguments args) { |
+ NoHandleAllocation ha; |
+ ASSERT(args.length() == 3); |
+ |
+ CONVERT_SMI_CHECKED(year, args[0]); |
+ CONVERT_SMI_CHECKED(month, args[1]); |
+ CONVERT_SMI_CHECKED(date, args[2]); |
+ |
+ return Smi::FromInt(MakeDay(year, month, date)); |
+} |
+ |
+ |
+static const int kDays4Years[] = {0, 365, 2 * 365, 3 * 365 + 1}; |
+static const int kDaysIn4Years = 4 * 365 + 1; |
+static const int kDaysIn100Years = 25 * kDaysIn4Years - 1; |
+static const int kDaysIn400Years = 4 * kDaysIn100Years + 1; |
+static const int kDays1970to2000 = 30 * 365 + 7; |
+static const int kDaysOffset = 1000 * kDaysIn400Years + 5 * kDaysIn400Years - |
+ kDays1970to2000; |
+static const int kYearsOffset = 400000; |
+ |
+static const char kDayInYear[] = { |
Mads Ager (chromium)
2010/03/12 08:00:21
Could you add a comment stating the start and end
|
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, |
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}; |
+ |
+static const char kMonthInYear[] = { |
Mads Ager (chromium)
2010/03/12 08:00:21
Comment with start and end year for this table?
|
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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 5, 5, 5, 5, |
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, |
+ 6, 6, 6, 6, 6, 6, |
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
+ 7, 7, 7, 7, 7, 7, |
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, |
+ 8, 8, 8, 8, 8, |
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
+ 9, 9, 9, 9, 9, 9, |
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, |
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, |
+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, |
+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11}; |
+ |
+ |
+// This function works for dates from 1970 to 2099. |
+static inline void DateYMDFromTimeAfter1970(int date, |
+ int &year, int &month, int &day) { |
Mads Ager (chromium)
2010/03/12 08:00:21
One parameter per line when splitting like this.
|
+#ifdef DEBUG |
+ int save_date = date; // Need this for ASSERTÂ in the end. |
+#endif |
+ |
+ year = 1970 + (4 * date + 2) / kDaysIn4Years; |
+ date %= kDaysIn4Years; |
+ |
+ month = kMonthInYear[date]; |
+ day = kDayInYear[date]; |
+ |
+ ASSERT(MakeDay(year, month, day) == save_date); |
+} |
+ |
+ |
+static inline void DateYMDFromTimeSlow(int date, |
+ int &year, int &month, int &day) { |
+#ifdef DEBUG |
+ int save_date = date; // Need this for ASSERTÂ in the end. |
+#endif |
+ |
+ date += kDaysOffset; |
+ year = 400 * (date / kDaysIn400Years) - kYearsOffset; |
+ date %= kDaysIn400Years; |
+ |
+ ASSERT(MakeDay(year, 0, 1) + date == save_date); |
+ |
+ date--; |
+ int yd1 = date / kDaysIn100Years; |
+ date %= kDaysIn100Years; |
+ year += 100 * yd1; |
+ |
+ date++; |
+ int yd2 = date / kDaysIn4Years; |
+ date %= kDaysIn4Years; |
+ year += 4 * yd2; |
+ |
+ date--; |
+ int yd3 = date / 365; |
+ date %= 365; |
+ year += yd3; |
+ |
+ bool is_leap = (!yd1 || yd2) && !yd3; |
+ |
+ ASSERT(date >= -1); |
+ ASSERT(is_leap || date >= 0); |
+ ASSERT(date < 365 || is_leap && date < 366); |
+ ASSERT(is_leap == (year % 4 == 0 && (year % 100 || (year % 400 == 0)))); |
+ ASSERT(is_leap || MakeDay(year, 0, 1) + date == save_date); |
+ ASSERT(!is_leap || MakeDay(year, 0, 1) + date + 1 == save_date); |
+ |
+ if (is_leap) { |
+ day = kDayInYear[2*365 + 1 + date]; |
+ month = kMonthInYear[2*365 + 1 + date]; |
+ } else { |
+ day = kDayInYear[date]; |
+ month = kMonthInYear[date]; |
+ } |
+ |
+ ASSERT(MakeDay(year, month, day) == save_date); |
+} |
+ |
+ |
+static inline void DateYMDFromTime(int date, |
+ int &year, int &month, int &day) { |
+ if (date >= 0 && date < 32 * kDaysIn4Years) { |
+ DateYMDFromTimeAfter1970(date, year, month, day); |
+ } else { |
+ DateYMDFromTimeSlow(date, year, month, day); |
+ } |
+} |
+ |
+ |
+static Object* Runtime_DateYMDFromTime(Arguments args) { |
+ NoHandleAllocation ha; |
+ ASSERT(args.length() == 2); |
+ |
+ CONVERT_DOUBLE_CHECKED(t, args[0]); |
+ CONVERT_CHECKED(JSArray, res_array, args[1]); |
+ |
+ int year, month, day; |
+ DateYMDFromTime(static_cast<int>(floor(t / 86400000)), year, month, day); |
+ |
+ res_array->SetElement(0, Smi::FromInt(year)); |
+ res_array->SetElement(1, Smi::FromInt(month)); |
+ res_array->SetElement(2, Smi::FromInt(day)); |
+ |
+ return Heap::undefined_value(); |
+} |
+ |
+ |
static Object* Runtime_NewArgumentsFast(Arguments args) { |
NoHandleAllocation ha; |
ASSERT(args.length() == 3); |