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

Side by Side Diff: src/date.js

Issue 844006: Merge changes up to V8 version 2.1.3 into the partial snapshots (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/partial_snapshots/
Patch Set: Created 10 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 | Annotate | Revision Log
« no previous file with comments | « src/data-flow.cc ('k') | src/debug.h » ('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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 106
107 function EquivalentTime(t) { 107 function EquivalentTime(t) {
108 // The issue here is that some library calls don't work right for dates 108 // The issue here is that some library calls don't work right for dates
109 // that cannot be represented using a non-negative signed 32 bit integer 109 // that cannot be represented using a non-negative signed 32 bit integer
110 // (measured in whole seconds based on the 1970 epoch). 110 // (measured in whole seconds based on the 1970 epoch).
111 // We solve this by mapping the time to a year with same leap-year-ness 111 // We solve this by mapping the time to a year with same leap-year-ness
112 // and same starting day for the year. The ECMAscript specification says 112 // and same starting day for the year. The ECMAscript specification says
113 // we must do this, but for compatibility with other browsers, we use 113 // we must do this, but for compatibility with other browsers, we use
114 // the actual year if it is in the range 1970..2037 114 // the actual year if it is in the range 1970..2037
115 if (t >= 0 && t <= 2.1e12) return t; 115 if (t >= 0 && t <= 2.1e12) return t;
116 var day = MakeDay(EquivalentYear(YEAR_FROM_TIME(t)), MONTH_FROM_TIME(t), DATE_ FROM_TIME(t)); 116
117 return TimeClip(MakeDate(day, TimeWithinDay(t))); 117 var day = MakeDay(EquivalentYear(YEAR_FROM_TIME(t)),
118 MONTH_FROM_TIME(t),
119 DATE_FROM_TIME(t));
120 return MakeDate(day, TimeWithinDay(t));
118 } 121 }
119 122
120 123
121 // Because computing the DST offset is a pretty expensive operation 124 // Because computing the DST offset is a pretty expensive operation
122 // we keep a cache of last computed offset along with a time interval 125 // we keep a cache of last computed offset along with a time interval
123 // where we know the cache is valid. 126 // where we know the cache is valid.
124 var DST_offset_cache = { 127 var DST_offset_cache = {
125 // Cached DST offset. 128 // Cached DST offset.
126 offset: 0, 129 offset: 0,
127 // Time interval where the cached offset is valid. 130 // Time interval where the cached offset is valid.
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 + TO_INTEGER(ms); 253 + TO_INTEGER(ms);
251 } 254 }
252 255
253 256
254 // ECMA 262 - 15.9.1.12 257 // ECMA 262 - 15.9.1.12
255 function TimeInYear(year) { 258 function TimeInYear(year) {
256 return DaysInYear(year) * msPerDay; 259 return DaysInYear(year) * msPerDay;
257 } 260 }
258 261
259 262
260 // Compute modified Julian day from year, month, date.
261 function ToJulianDay(year, month, date) {
262 var jy = (month > 1) ? year : year - 1;
263 var jm = (month > 1) ? month + 2 : month + 14;
264 var ja = FLOOR(jy / 100);
265 return FLOOR(FLOOR(365.25*jy) + FLOOR(30.6001*jm) + date + 1720995) + 2 - ja + FLOOR(0.25*ja);
266 }
267
268 var four_year_cycle_table = CalculateDateTable(); 263 var four_year_cycle_table = CalculateDateTable();
269 264
270 265
271 function CalculateDateTable() { 266 function CalculateDateTable() {
272 var month_lengths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; 267 var month_lengths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
273 var four_year_cycle_table = new $Array(1461); 268 var four_year_cycle_table = new $Array(1461);
274 269
275 var cumulative = 0; 270 var cumulative = 0;
276 var position = 0; 271 var position = 0;
277 var leap_position = 0; 272 var leap_position = 0;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 347
353 // Compute number of days given a year, month, date. 348 // Compute number of days given a year, month, date.
354 // Note that month and date can lie outside the normal range. 349 // Note that month and date can lie outside the normal range.
355 // For example: 350 // For example:
356 // MakeDay(2007, -4, 20) --> MakeDay(2006, 8, 20) 351 // MakeDay(2007, -4, 20) --> MakeDay(2006, 8, 20)
357 // MakeDay(2007, -33, 1) --> MakeDay(2004, 3, 1) 352 // MakeDay(2007, -33, 1) --> MakeDay(2004, 3, 1)
358 // MakeDay(2007, 14, -50) --> MakeDay(2007, 8, 11) 353 // MakeDay(2007, 14, -50) --> MakeDay(2007, 8, 11)
359 function MakeDay(year, month, date) { 354 function MakeDay(year, month, date) {
360 if (!$isFinite(year) || !$isFinite(month) || !$isFinite(date)) return $NaN; 355 if (!$isFinite(year) || !$isFinite(month) || !$isFinite(date)) return $NaN;
361 356
362 // Conversion to integers.
363 year = TO_INTEGER(year); 357 year = TO_INTEGER(year);
364 month = TO_INTEGER(month); 358 month = TO_INTEGER(month);
365 date = TO_INTEGER(date); 359 date = TO_INTEGER(date);
366 360
367 // Overflow months into year. 361 if (year < kMinYear || year > kMaxYear ||
368 year = year + FLOOR(month/12); 362 month < kMinMonth || month > kMaxMonth ||
369 month = month % 12; 363 date < kMinDate || date > kMaxDate) {
370 if (month < 0) { 364 return $NaN;
371 month += 12;
372 } 365 }
373 366
374 // Return days relative to Jan 1 1970. 367 // Now we rely on year, month and date being SMIs.
375 return ToJulianDay(year, month, date) - kDayZeroInJulianDay; 368 return %DateMakeDay(year, month, date);
376 } 369 }
377 370
378 371
379 // ECMA 262 - 15.9.1.13 372 // ECMA 262 - 15.9.1.13
380 function MakeDate(day, time) { 373 function MakeDate(day, time) {
381 if (!$isFinite(day)) return $NaN; 374 if (!$isFinite(day)) return $NaN;
382 if (!$isFinite(time)) return $NaN; 375 if (!$isFinite(time)) return $NaN;
383 return day * msPerDay + time; 376 return day * msPerDay + time;
384 } 377 }
385 378
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 "toGMTString", DateToGMTString, 1122 "toGMTString", DateToGMTString,
1130 "toUTCString", DateToUTCString, 1123 "toUTCString", DateToUTCString,
1131 "getYear", DateGetYear, 1124 "getYear", DateGetYear,
1132 "setYear", DateSetYear, 1125 "setYear", DateSetYear,
1133 "toISOString", DateToISOString, 1126 "toISOString", DateToISOString,
1134 "toJSON", DateToJSON 1127 "toJSON", DateToJSON
1135 )); 1128 ));
1136 } 1129 }
1137 1130
1138 SetupDate(); 1131 SetupDate();
OLDNEW
« no previous file with comments | « src/data-flow.cc ('k') | src/debug.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698