Changeset 20203 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- Mar 14, 2007, 7:21:47 PM (18 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/DateMath.cpp
r19945 r20203 45 45 #include <math.h> 46 46 #include <stdint.h> 47 #include <value.h> 48 49 #include <wtf/Assertions.h> 47 50 48 51 #if PLATFORM(DARWIN) … … 268 271 } 269 272 273 double getCurrentUTCTime() 274 { 275 #if PLATFORM(WIN_OS) 276 #if COMPILER(BORLAND) 277 struct timeb timebuffer; 278 ftime(&timebuffer); 279 #else 280 struct _timeb timebuffer; 281 _ftime(&timebuffer); 282 #endif 283 double utc = timebuffer.time * msPerSecond + timebuffer.millitm; 284 #else 285 struct timeval tv; 286 gettimeofday(&tv, 0); 287 double utc = floor(tv.tv_sec * msPerSecond + tv.tv_usec / 1000); 288 #endif 289 return utc; 290 } 291 292 // There is a hard limit at 2038 that we currently do not have a workaround 293 // for (rdar://problem/5052975). 294 static inline int maximumYearForDST() 295 { 296 return 2037; 297 } 298 299 // It is ok if the cached year is not the current year (e.g. Dec 31st) 300 // so long as the rules for DST did not change between the two years, if it does 301 // the app would need to be restarted. 302 static int mimimumYearForDST() 303 { 304 // Because of the 2038 issue (see maximumYearForDST) if the current year is 305 // greater than the max year minus 27 (2010), we want to use the max year 306 // minus 27 instead, to ensure there is a range of 28 years that all years 307 // can map to. 308 static int minYear = std::min(msToYear(getCurrentUTCTime()), maximumYearForDST()-27) ; 309 return minYear; 310 } 311 270 312 /* 271 * Find a year for which any given date will fall on the same weekday. 272 * 273 * This function should be used with caution when used other than 274 * for determining DST; it hasn't been proven not to produce an 275 * incorrect year for times near year boundaries. 313 * Find an equivalent year for the one given, where equivalence is deterined by 314 * the two years having the same leapness and the first day of the year, falling 315 * on the same day of the week. 316 * 317 * This function returns a year between this current year and 2037, however this 318 * function will potentially return incorrect results if the current year is after 319 * 2010, (rdar://problem/5052975), if the year passed in is before 1900 or after 320 * 2100, (rdar://problem/5055038). 276 321 */ 277 322 int equivalentYearForDST(int year) 278 323 { 279 int difference = 2000 - year; // Arbitrary year around which most dates equivalence is correct 280 int quotient = difference / 28; // Integer division, no remainder. 281 int product = quotient * 28; 282 return year + product; 324 static int minYear = mimimumYearForDST(); 325 static int maxYear = maximumYearForDST(); 326 327 int difference; 328 if (year > maxYear) 329 difference = minYear - year; 330 else if (year < minYear) 331 difference = maxYear - year; 332 else 333 return year; 334 335 int quotient = difference / 28; 336 int product = (quotient) * 28; 337 338 year += product; 339 ASSERT((year >= minYear && year <= maxYear) || (product - year == static_cast<int>(NaN))); 340 return year; 283 341 } 284 342 … … 377 435 // determining DST. For this reason we shift away from years that localtime can handle but would 378 436 // return historically accurate information. 379 380 // if before Jan 01, 2000 12:00:00 AM UTC or after Jan 01, 2038 12:00:00 AM UTC 381 if (ms < 946684800000.0 || ms > 2145916800000.0) { 382 int year = equivalentYearForDST(msToYear(ms)); 383 int day = dateToDayInYear(year, msToMonth(ms), msToDayInMonth(ms)); 437 int year = msToYear(ms); 438 int equvalentYear = equivalentYearForDST(year); 439 if (year != equvalentYear) { 440 int day = dateToDayInYear(equvalentYear, msToMonth(ms), msToDayInMonth(ms)); 384 441 ms = (day * msPerDay) + msToMilliseconds(ms); 385 442 } -
trunk/JavaScriptCore/kjs/DateMath.h
r19945 r20203 54 54 double getUTCOffset(); 55 55 int equivalentYearForDST(int year); 56 double getCurrentUTCTime(); 56 57 57 58 const char * const weekdayName[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
Note:
See TracChangeset
for help on using the changeset viewer.