Index: src/runtime.cc |
=================================================================== |
--- src/runtime.cc (revision 3986) |
+++ src/runtime.cc (working copy) |
@@ -4930,6 +4930,38 @@ |
} |
+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 const int day_from_month[] = {0, 31, 59, 90, 120, 151, |
+ 181, 212, 243, 273, 304, 334}; |
+ static const int day_from_month_leap[] = {0, 31, 60, 91, 121, 152, |
+ 182, 213, 244, 274, 305, 335}; |
+ |
+ year += month / 12; |
+ month %= 12; |
+ if (month < 0) { |
+ year--; |
+ month += 12; |
+ } |
+ |
+ static const int base_day = 365*1970 + 1969/4 - 1969/100 + 1969/400; |
+ |
+ int day_from_year = 365*year + (year - 1)/4 - (year - 1)/100 + (year - 1)/400 - base_day; |
Mads Ager (chromium)
2010/03/02 13:04:08
Line too long, please reformat. Also, please have
Oleg Eterevsky
2010/03/02 13:28:23
I tried to reformat it to make it more readable, a
|
+ |
+ if (year % 4 || (year % 100 == 0 && year % 400 != 0)) { |
+ return Smi::FromInt(day_from_year + day_from_month[month] + date - 1); |
+ } else { |
+ return Smi::FromInt(day_from_year + day_from_month_leap[month] + date - 1); |
+ } |
+} |
+ |
+ |
static Object* Runtime_NewArgumentsFast(Arguments args) { |
NoHandleAllocation ha; |
ASSERT(args.length() == 3); |