Changeset 50711 in webkit for trunk/JavaScriptCore/wtf/DateMath.cpp
- Timestamp:
- Nov 9, 2009, 8:14:34 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/DateMath.cpp
r50705 r50711 40 40 * If you do not delete the provisions above, a recipient may use your 41 41 * version of this file under any of the LGPL, the MPL or the GPL. 42 43 * Copyright 2006-2008 the V8 project authors. All rights reserved. 44 * Redistribution and use in source and binary forms, with or without 45 * modification, are permitted provided that the following conditions are 46 * met: 47 * 48 * * Redistributions of source code must retain the above copyright 49 * notice, this list of conditions and the following disclaimer. 50 * * Redistributions in binary form must reproduce the above 51 * copyright notice, this list of conditions and the following 52 * disclaimer in the documentation and/or other materials provided 53 * with the distribution. 54 * * Neither the name of Google Inc. nor the names of its 55 * contributors may be used to endorse or promote products derived 56 * from this software without specific prior written permission. 57 * 58 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 59 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 60 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 61 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 62 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 63 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 64 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 65 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 66 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 67 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 68 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 42 69 */ 43 70 … … 381 408 382 409 /* 383 * Get the DST offset for the time passed in. Takes 384 * seconds (not milliseconds) and cannot handle dates before 1970 385 * on some OS' 410 * Get the DST offset for the time passed in. 386 411 */ 387 static double getDSTOffsetSimple(double localTimeSeconds, double utcOffset)412 static double calculateDSTOffsetSimple(double localTimeSeconds, double utcOffset) 388 413 { 389 414 if (localTimeSeconds > maxUnixTime) … … 414 439 415 440 // Get the DST offset, given a time in UTC 416 static double getDSTOffset(double ms, double utcOffset)417 { 418 // On Mac OS X, the call to localtime (see getDSTOffsetSimple) will return historically accurate441 static double calculateDSTOffset(double ms, double utcOffset) 442 { 443 // On Mac OS X, the call to localtime (see calculateDSTOffsetSimple) will return historically accurate 419 444 // DST information (e.g. New Zealand did not have DST from 1946 to 1974) however the JavaScript 420 445 // standard explicitly dictates that historical information should not be considered when … … 432 457 } 433 458 434 return getDSTOffsetSimple(ms / msPerSecond, utcOffset);459 return calculateDSTOffsetSimple(ms / msPerSecond, utcOffset); 435 460 } 436 461 … … 803 828 if (!haveTZ) { 804 829 double utcOffset = calculateUTCOffset(); 805 double dstOffset = getDSTOffset(ms, utcOffset);830 double dstOffset = calculateDSTOffset(ms, utcOffset); 806 831 offset = static_cast<int>((utcOffset + dstOffset) / msPerMinute); 807 832 } … … 821 846 #if USE(JSC) 822 847 namespace JSC { 848 849 // Get the DST offset for the time passed in. 850 // 851 // NOTE: The implementation relies on the fact that no time zones have 852 // more than one daylight savings offset change per month. 853 // If this function is called with NaN it returns NaN. 854 static double getDSTOffset(ExecState* exec, double ms, double utcOffset) 855 { 856 DSTOffsetCache& cache = exec->globalData().dstOffsetCache; 857 double start = cache.start; 858 double end = cache.end; 859 860 if (start <= ms) { 861 // If the time fits in the cached interval, return the cached offset. 862 if (ms <= end) return cache.offset; 863 864 // Compute a possible new interval end. 865 double newEnd = end + cache.increment; 866 867 if (ms <= newEnd) { 868 double endOffset = calculateDSTOffset(newEnd, utcOffset); 869 if (cache.offset == endOffset) { 870 // If the offset at the end of the new interval still matches 871 // the offset in the cache, we grow the cached time interval 872 // and return the offset. 873 cache.end = newEnd; 874 cache.increment = msPerMonth; 875 return endOffset; 876 } else { 877 double offset = calculateDSTOffset(ms, utcOffset); 878 if (offset == endOffset) { 879 // The offset at the given time is equal to the offset at the 880 // new end of the interval, so that means that we've just skipped 881 // the point in time where the DST offset change occurred. Updated 882 // the interval to reflect this and reset the increment. 883 cache.start = ms; 884 cache.end = newEnd; 885 cache.increment = msPerMonth; 886 } else { 887 // The interval contains a DST offset change and the given time is 888 // before it. Adjust the increment to avoid a linear search for 889 // the offset change point and change the end of the interval. 890 cache.increment /= 3; 891 cache.end = ms; 892 } 893 // Update the offset in the cache and return it. 894 cache.offset = offset; 895 return offset; 896 } 897 } 898 } 899 900 // Compute the DST offset for the time and shrink the cache interval 901 // to only contain the time. This allows fast repeated DST offset 902 // computations for the same time. 903 double offset = calculateDSTOffset(ms, utcOffset); 904 cache.offset = offset; 905 cache.start = ms; 906 cache.end = ms; 907 cache.increment = msPerMonth; 908 return offset; 909 } 910 823 911 /* 824 912 * Get the difference in milliseconds between this time zone and UTC (GMT) … … 843 931 double utcOffset = getUTCOffset(exec); 844 932 result -= utcOffset; 845 result -= getDSTOffset( result, utcOffset);933 result -= getDSTOffset(exec, result, utcOffset); 846 934 } 847 935 … … 856 944 if (!outputIsUTC) { 857 945 utcOff = getUTCOffset(exec); 858 dstOff = getDSTOffset( ms, utcOff);946 dstOff = getDSTOffset(exec, ms, utcOff); 859 947 ms += dstOff + utcOff; 860 948 } … … 883 971 if (!haveTZ) { 884 972 double utcOffset = getUTCOffset(exec); 885 double dstOffset = getDSTOffset( ms, utcOffset);973 double dstOffset = getDSTOffset(exec, ms, utcOffset); 886 974 offset = static_cast<int>((utcOffset + dstOffset) / WTF::msPerMinute); 887 975 }
Note:
See TracChangeset
for help on using the changeset viewer.