Changeset 100205 in webkit
- Timestamp:
- Nov 14, 2011 4:04:53 PM (12 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 1 added
- 15 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/CMakeLists.txt
r100081 r100205 147 147 runtime/JSByteArray.cpp 148 148 runtime/JSCell.cpp 149 runtime/JSDateMath.cpp 149 150 runtime/JSFunction.cpp 150 151 runtime/JSBoundFunction.cpp -
trunk/Source/JavaScriptCore/ChangeLog
r100202 r100205 1 2011-11-14 Adam Barth <abarth@webkit.org> 2 3 DateMath.cpp should not depend on JavaScriptCore 4 https://bugs.webkit.org/show_bug.cgi?id=71747 5 6 Reviewed by Darin Adler. 7 8 This patch moves the JSC-specific parts of DateMath into JSDateMath in 9 JavaScriptCore. There shouldn't be any behavior change. 10 11 * CMakeLists.txt: 12 * GNUmakefile.list.am: 13 * JavaScriptCore.gypi: 14 * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj: 15 * JavaScriptCore.xcodeproj/project.pbxproj: 16 * Target.pri: 17 * runtime/DateConstructor.cpp: 18 * runtime/DateConversion.cpp: 19 * runtime/DateInstance.cpp: 20 * runtime/DateInstanceCache.h: 21 * runtime/DatePrototype.cpp: 22 * runtime/InitializeThreading.cpp: 23 * runtime/JSDateMath.cpp: Copied from Source/JavaScriptCore/wtf/DateMath.cpp. 24 (JSC::timeToMS): 25 (JSC::msToSeconds): 26 * runtime/JSDateMath.h: Copied from Source/JavaScriptCore/wtf/DateMath.h. 27 * wtf/DateMath.cpp: 28 (WTF::isLeapYear): 29 (WTF::msToDays): 30 (WTF::msToMinutes): 31 (WTF::msToHours): 32 (WTF::parseDateFromNullTerminatedCharacters): 33 (WTF::makeRFC2822DateString): 34 * wtf/DateMath.h: 35 1 36 2011-11-14 Michael Saboff <msaboff@apple.com> 2 37 -
trunk/Source/JavaScriptCore/GNUmakefile.list.am
r100115 r100205 381 381 Source/JavaScriptCore/runtime/JSCell.cpp \ 382 382 Source/JavaScriptCore/runtime/JSCell.h \ 383 Source/JavaScriptCore/runtime/JSDateMath.cpp \ 384 Source/JavaScriptCore/runtime/JSDateMath.h \ 383 385 Source/JavaScriptCore/runtime/JSFunction.cpp \ 384 386 Source/JavaScriptCore/runtime/JSFunction.h \ -
trunk/Source/JavaScriptCore/JavaScriptCore.gypi
r98909 r100205 84 84 'runtime/JSByteArray.h', 85 85 'runtime/JSCell.h', 86 'runtime/JSDateMath.h', 86 87 'runtime/JSFunction.h', 87 88 'runtime/JSBoundFunction.h', … … 478 479 'runtime/JSByteArray.cpp', 479 480 'runtime/JSCell.cpp', 481 'runtime/JSDateMath.cpp', 480 482 'runtime/JSFunction.cpp', 481 483 'runtime/JSBoundFunction.cpp', -
trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj
r98909 r100205 799 799 </File> 800 800 <File 801 RelativePath="..\..\runtime\JSDateMath.cpp" 802 > 803 </File> 804 <File 805 RelativePath="..\..\runtime\JSDateMath.h" 806 > 807 </File> 808 <File 801 809 RelativePath="..\..\runtime\JSFunction.cpp" 802 810 > -
trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r100197 r100205 439 439 96DD73790F9DA3100027FBCC /* VMTags.h in Headers */ = {isa = PBXBuildFile; fileRef = 96DD73780F9DA3100027FBCC /* VMTags.h */; settings = {ATTRIBUTES = (Private, ); }; }; 440 440 971EDEA61169E0D3005E4262 /* Terminator.h in Headers */ = {isa = PBXBuildFile; fileRef = 97F6903A1169DF7F00A6BB46 /* Terminator.h */; settings = {ATTRIBUTES = (Private, ); }; }; 441 978801401471AD920041B016 /* JSDateMath.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9788FC221471AD0C0068CE2D /* JSDateMath.cpp */; }; 442 978801411471AD920041B016 /* JSDateMath.h in Headers */ = {isa = PBXBuildFile; fileRef = 9788FC231471AD0C0068CE2D /* JSDateMath.h */; settings = {ATTRIBUTES = (Private, ); }; }; 441 443 97941A5713029AAB004A3447 /* OSRandomSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97941A3F130299DB004A3447 /* OSRandomSource.cpp */; }; 442 444 97941A5A13029ACC004A3447 /* OSRandomSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 97941A40130299DB004A3447 /* OSRandomSource.h */; }; … … 1248 1250 969A09220ED1E09C00F1F681 /* Completion.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Completion.cpp; sourceTree = "<group>"; }; 1249 1251 96DD73780F9DA3100027FBCC /* VMTags.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VMTags.h; sourceTree = "<group>"; }; 1252 9788FC221471AD0C0068CE2D /* JSDateMath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDateMath.cpp; sourceTree = "<group>"; }; 1253 9788FC231471AD0C0068CE2D /* JSDateMath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDateMath.h; sourceTree = "<group>"; }; 1250 1254 97941A3F130299DB004A3447 /* OSRandomSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OSRandomSource.cpp; sourceTree = "<group>"; }; 1251 1255 97941A40130299DB004A3447 /* OSRandomSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSRandomSource.h; sourceTree = "<group>"; }; … … 2141 2145 BC7F8FBA0E19D1EF008632C0 /* JSCell.cpp */, 2142 2146 BC1167D80E19BCC9008066DD /* JSCell.h */, 2147 9788FC221471AD0C0068CE2D /* JSDateMath.cpp */, 2148 9788FC231471AD0C0068CE2D /* JSDateMath.h */, 2143 2149 F692A85E0255597D01FF60F7 /* JSFunction.cpp */, 2144 2150 F692A85F0255597D01FF60F7 /* JSFunction.h */, … … 2934 2940 0F431738146BAC69007E3890 /* ListableHandler.h in Headers */, 2935 2941 0F5F08CF146C7633000472A9 /* UnconditionalFinalizer.h in Headers */, 2942 978801411471AD920041B016 /* JSDateMath.h in Headers */, 2936 2943 ); 2937 2944 runOnlyForDeploymentPostprocessing = 0; … … 3471 3478 0FC0979E146B272100CF2442 /* DFGCorrectableJumpPoint.cpp in Sources */, 3472 3479 0FC097A1146B28CA00CF2442 /* DFGThunks.cpp in Sources */, 3480 978801401471AD920041B016 /* JSDateMath.cpp in Sources */, 3473 3481 ); 3474 3482 runOnlyForDeploymentPostprocessing = 0; -
trunk/Source/JavaScriptCore/Target.pri
r99787 r100205 165 165 runtime/JSByteArray.cpp \ 166 166 runtime/JSCell.cpp \ 167 runtime/JSDateMath.cpp \ 167 168 runtime/JSFunction.cpp \ 168 169 runtime/JSBoundFunction.cpp \ -
trunk/Source/JavaScriptCore/runtime/DateConstructor.cpp
r100006 r100205 26 26 #include "DateInstance.h" 27 27 #include "DatePrototype.h" 28 #include "JSDateMath.h" 28 29 #include "JSFunction.h" 29 30 #include "JSGlobalObject.h" … … 33 34 #include <math.h> 34 35 #include <time.h> 35 #include <wtf/DateMath.h>36 36 #include <wtf/MathExtras.h> 37 37 -
trunk/Source/JavaScriptCore/runtime/DateConversion.cpp
r81040 r100205 45 45 46 46 #include "CallFrame.h" 47 #include "JSDateMath.h" 47 48 #include "JSObject.h" 48 49 #include "ScopeChain.h" 49 50 #include "UString.h" 50 #include <wtf/DateMath.h>51 51 #include <wtf/StringExtras.h> 52 52 #include <wtf/text/CString.h> -
trunk/Source/JavaScriptCore/runtime/DateInstance.cpp
r95936 r100205 23 23 #include "DateInstance.h" 24 24 25 #include "JSDateMath.h" 25 26 #include "JSGlobalObject.h" 26 27 27 28 #include <math.h> 28 #include <wtf/DateMath.h>29 29 #include <wtf/MathExtras.h> 30 30 -
trunk/Source/JavaScriptCore/runtime/DateInstanceCache.h
r95901 r100205 27 27 #define DateInstanceCache_h 28 28 29 #include <wtf/DateMath.h>29 #include "JSDateMath.h" 30 30 #include <wtf/FixedArray.h> 31 31 #include <wtf/HashFunctions.h> -
trunk/Source/JavaScriptCore/runtime/DatePrototype.cpp
r100037 r100205 28 28 #include "DateInstance.h" 29 29 #include "Error.h" 30 #include "JSDateMath.h" 30 31 #include "JSGlobalObject.h" 31 32 #include "JSString.h" … … 44 45 #include <time.h> 45 46 #include <wtf/Assertions.h> 46 #include <wtf/DateMath.h>47 47 #include <wtf/MathExtras.h> 48 48 #include <wtf/StringExtras.h> -
trunk/Source/JavaScriptCore/runtime/InitializeThreading.cpp
r96463 r100205 34 34 #include "Heuristics.h" 35 35 #include "Identifier.h" 36 #include "JSDateMath.h" 36 37 #include "JSGlobalObject.h" 37 38 #include "UString.h" 38 39 #include "WriteBarrier.h" 39 40 #include "dtoa.h" 40 #include <wtf/DateMath.h>41 41 #include <wtf/Threading.h> 42 42 #include <wtf/dtoa/cached-powers.h> -
trunk/Source/JavaScriptCore/runtime/JSDateMath.h
r100204 r100205 41 41 */ 42 42 43 #ifndef DateMath_h44 #define DateMath_h43 #ifndef JSDateMath_h 44 #define JSDateMath_h 45 45 46 #include <math.h> 47 #include <stdint.h> 48 #include <string.h> 49 #include <time.h> 50 #include <wtf/CurrentTime.h> 51 #include <wtf/Noncopyable.h> 52 #include <wtf/OwnArrayPtr.h> 53 #include <wtf/PassOwnArrayPtr.h> 54 #include <wtf/text/WTFString.h> 55 #include <wtf/UnusedParam.h> 46 #include <wtf/DateMath.h> 56 47 57 namespace WTF { 58 void initializeDates(); 59 int equivalentYearForDST(int year); 48 namespace JSC { 60 49 61 // Not really math related, but this is currently the only shared place to put these.62 double parseES5DateFromNullTerminatedCharacters(const char* dateString);63 double parseDateFromNullTerminatedCharacters(const char* dateString);64 double timeClip(double);65 // dayOfWeek: [0, 6] 0 being Monday, day: [1, 31], month: [0, 11], year: ex: 2011, hours: [0, 23], minutes: [0, 59], seconds: [0, 59], utcOffset: [-720,720].66 String makeRFC2822DateString(unsigned dayOfWeek, unsigned day, unsigned month, unsigned year, unsigned hours, unsigned minutes, unsigned seconds, int utcOffset);67 68 inline double jsCurrentTime()69 {70 // JavaScript doesn't recognize fractions of a millisecond.71 return floor(WTF::currentTimeMS());72 }73 74 const char * const weekdayName[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };75 const char * const monthName[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };76 77 const double hoursPerDay = 24.0;78 const double minutesPerHour = 60.0;79 const double secondsPerHour = 60.0 * 60.0;80 const double secondsPerMinute = 60.0;81 const double msPerSecond = 1000.0;82 const double msPerMinute = 60.0 * 1000.0;83 const double msPerHour = 60.0 * 60.0 * 1000.0;84 const double msPerDay = 24.0 * 60.0 * 60.0 * 1000.0;85 const double msPerMonth = 2592000000.0;86 87 // Returns the number of days from 1970-01-01 to the specified date.88 double dateToDaysFrom1970(int year, int month, int day);89 int msToYear(double ms);90 int dayInYear(double ms, int year);91 int monthFromDayInYear(int dayInYear, bool leapYear);92 int dayInMonthFromDayInYear(int dayInYear, bool leapYear);93 94 // Returns offset milliseconds for UTC and DST.95 int32_t calculateUTCOffset();96 double calculateDSTOffset(double ms, double utcOffset);97 98 } // namespace WTF99 100 using WTF::adoptArrayPtr;101 using WTF::dateToDaysFrom1970;102 using WTF::dayInMonthFromDayInYear;103 using WTF::dayInYear;104 using WTF::minutesPerHour;105 using WTF::monthFromDayInYear;106 using WTF::msPerDay;107 using WTF::msPerMinute;108 using WTF::msPerSecond;109 using WTF::msToYear;110 using WTF::secondsPerMinute;111 using WTF::parseDateFromNullTerminatedCharacters;112 using WTF::makeRFC2822DateString;113 using WTF::calculateUTCOffset;114 using WTF::calculateDSTOffset;115 116 #if USE(JSC)117 namespace JSC {118 50 class ExecState; 119 51 struct GregorianDateTime; … … 232 164 return t.utcOffset; 233 165 } 166 234 167 } // namespace JSC 235 #endif // USE(JSC)236 168 237 #endif // DateMath_h169 #endif // JSDateMath_h -
trunk/Source/JavaScriptCore/wtf/DateMath.cpp
r95555 r100205 76 76 #include "ASCIICType.h" 77 77 #include "CurrentTime.h" 78 #if USE(JSC)79 #include "JSObject.h"80 #endif81 78 #include "MathExtras.h" 82 #if USE(JSC)83 #include "ScopeChain.h"84 #endif85 79 #include "StdLibExtras.h" 86 80 #include "StringExtras.h" … … 110 104 #endif 111 105 112 #if USE(JSC)113 #include "CallFrame.h"114 #endif115 116 106 using namespace WTF; 117 107 … … 139 129 }; 140 130 141 static inlinebool isLeapYear(int year)131 bool isLeapYear(int year) 142 132 { 143 133 if (year % 4 != 0) … … 174 164 } 175 165 176 static inlinedouble msToDays(double ms)166 double msToDays(double ms) 177 167 { 178 168 return floor(ms / msPerDay); … … 211 201 } 212 202 213 // 0: Sunday, 1: Monday, etc. 214 static inline int msToWeekDay(double ms) 215 { 216 int wd = (static_cast<int>(msToDays(ms)) + 4) % 7; 217 if (wd < 0) 218 wd += 7; 219 return wd; 220 } 221 222 static inline int msToSeconds(double ms) 223 { 224 double result = fmod(floor(ms / msPerSecond), secondsPerMinute); 225 if (result < 0) 226 result += secondsPerMinute; 227 return static_cast<int>(result); 228 } 229 230 static inline int msToMinutes(double ms) 203 int msToMinutes(double ms) 231 204 { 232 205 double result = fmod(floor(ms / msPerMinute), minutesPerHour); … … 236 209 } 237 210 238 static inlineint msToHours(double ms)211 int msToHours(double ms) 239 212 { 240 213 double result = fmod(floor(ms/msPerHour), hoursPerDay); … … 320 293 } 321 294 322 static inline double timeToMS(double hour, double min, double sec, double ms)323 {324 return (((hour * minutesPerHour + min) * secondsPerMinute + sec) * msPerSecond + ms);325 }326 327 295 double dateToDaysFrom1970(int year, int month, int day) 328 296 { … … 725 693 726 694 // Odd case where 'exec' is allowed to be 0, to accomodate a caller in WebCore. 727 staticdouble parseDateFromNullTerminatedCharacters(const char* dateString, bool& haveTZ, int& offset)695 double parseDateFromNullTerminatedCharacters(const char* dateString, bool& haveTZ, int& offset) 728 696 { 729 697 haveTZ = false; … … 1049 1017 return stringBuilder.toString(); 1050 1018 } 1019 1051 1020 } // namespace WTF 1052 1053 #if USE(JSC)1054 namespace JSC {1055 1056 // Get the DST offset for the time passed in.1057 //1058 // NOTE: The implementation relies on the fact that no time zones have1059 // more than one daylight savings offset change per month.1060 // If this function is called with NaN it returns NaN.1061 static double getDSTOffset(ExecState* exec, double ms, double utcOffset)1062 {1063 DSTOffsetCache& cache = exec->globalData().dstOffsetCache;1064 double start = cache.start;1065 double end = cache.end;1066 1067 if (start <= ms) {1068 // If the time fits in the cached interval, return the cached offset.1069 if (ms <= end) return cache.offset;1070 1071 // Compute a possible new interval end.1072 double newEnd = end + cache.increment;1073 1074 if (ms <= newEnd) {1075 double endOffset = calculateDSTOffset(newEnd, utcOffset);1076 if (cache.offset == endOffset) {1077 // If the offset at the end of the new interval still matches1078 // the offset in the cache, we grow the cached time interval1079 // and return the offset.1080 cache.end = newEnd;1081 cache.increment = msPerMonth;1082 return endOffset;1083 } else {1084 double offset = calculateDSTOffset(ms, utcOffset);1085 if (offset == endOffset) {1086 // The offset at the given time is equal to the offset at the1087 // new end of the interval, so that means that we've just skipped1088 // the point in time where the DST offset change occurred. Updated1089 // the interval to reflect this and reset the increment.1090 cache.start = ms;1091 cache.end = newEnd;1092 cache.increment = msPerMonth;1093 } else {1094 // The interval contains a DST offset change and the given time is1095 // before it. Adjust the increment to avoid a linear search for1096 // the offset change point and change the end of the interval.1097 cache.increment /= 3;1098 cache.end = ms;1099 }1100 // Update the offset in the cache and return it.1101 cache.offset = offset;1102 return offset;1103 }1104 }1105 }1106 1107 // Compute the DST offset for the time and shrink the cache interval1108 // to only contain the time. This allows fast repeated DST offset1109 // computations for the same time.1110 double offset = calculateDSTOffset(ms, utcOffset);1111 cache.offset = offset;1112 cache.start = ms;1113 cache.end = ms;1114 cache.increment = msPerMonth;1115 return offset;1116 }1117 1118 /*1119 * Get the difference in milliseconds between this time zone and UTC (GMT)1120 * NOT including DST.1121 */1122 double getUTCOffset(ExecState* exec)1123 {1124 double utcOffset = exec->globalData().cachedUTCOffset;1125 if (!isnan(utcOffset))1126 return utcOffset;1127 exec->globalData().cachedUTCOffset = calculateUTCOffset();1128 return exec->globalData().cachedUTCOffset;1129 }1130 1131 double gregorianDateTimeToMS(ExecState* exec, const GregorianDateTime& t, double milliSeconds, bool inputIsUTC)1132 {1133 double day = dateToDaysFrom1970(t.year + 1900, t.month, t.monthDay);1134 double ms = timeToMS(t.hour, t.minute, t.second, milliSeconds);1135 double result = (day * WTF::msPerDay) + ms;1136 1137 if (!inputIsUTC) { // convert to UTC1138 double utcOffset = getUTCOffset(exec);1139 result -= utcOffset;1140 result -= getDSTOffset(exec, result, utcOffset);1141 }1142 1143 return result;1144 }1145 1146 // input is UTC1147 void msToGregorianDateTime(ExecState* exec, double ms, bool outputIsUTC, GregorianDateTime& tm)1148 {1149 double dstOff = 0.0;1150 double utcOff = 0.0;1151 if (!outputIsUTC) {1152 utcOff = getUTCOffset(exec);1153 dstOff = getDSTOffset(exec, ms, utcOff);1154 ms += dstOff + utcOff;1155 }1156 1157 const int year = msToYear(ms);1158 tm.second = msToSeconds(ms);1159 tm.minute = msToMinutes(ms);1160 tm.hour = msToHours(ms);1161 tm.weekDay = msToWeekDay(ms);1162 tm.yearDay = dayInYear(ms, year);1163 tm.monthDay = dayInMonthFromDayInYear(tm.yearDay, isLeapYear(year));1164 tm.month = monthFromDayInYear(tm.yearDay, isLeapYear(year));1165 tm.year = year - 1900;1166 tm.isDST = dstOff != 0.0;1167 tm.utcOffset = static_cast<long>((dstOff + utcOff) / WTF::msPerSecond);1168 tm.timeZone = nullptr;1169 }1170 1171 double parseDateFromNullTerminatedCharacters(ExecState* exec, const char* dateString)1172 {1173 ASSERT(exec);1174 bool haveTZ;1175 int offset;1176 double ms = WTF::parseDateFromNullTerminatedCharacters(dateString, haveTZ, offset);1177 if (isnan(ms))1178 return std::numeric_limits<double>::quiet_NaN();1179 1180 // fall back to local timezone1181 if (!haveTZ) {1182 double utcOffset = getUTCOffset(exec);1183 double dstOffset = getDSTOffset(exec, ms, utcOffset);1184 offset = static_cast<int>((utcOffset + dstOffset) / WTF::msPerMinute);1185 }1186 return ms - (offset * WTF::msPerMinute);1187 }1188 1189 } // namespace JSC1190 #endif // USE(JSC) -
trunk/Source/JavaScriptCore/wtf/DateMath.h
r87958 r100205 56 56 57 57 namespace WTF { 58 58 59 void initializeDates(); 59 60 int equivalentYearForDST(int year); … … 62 63 double parseES5DateFromNullTerminatedCharacters(const char* dateString); 63 64 double parseDateFromNullTerminatedCharacters(const char* dateString); 65 double parseDateFromNullTerminatedCharacters(const char* dateString, bool& haveTZ, int& offset); 64 66 double timeClip(double); 65 67 // dayOfWeek: [0, 6] 0 being Monday, day: [1, 31], month: [0, 11], year: ex: 2011, hours: [0, 23], minutes: [0, 59], seconds: [0, 59], utcOffset: [-720,720]. … … 72 74 } 73 75 74 const char 75 const char 76 const char* const weekdayName[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" }; 77 const char* const monthName[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; 76 78 77 79 const double hoursPerDay = 24.0; … … 85 87 const double msPerMonth = 2592000000.0; 86 88 89 bool isLeapYear(int year); 90 87 91 // Returns the number of days from 1970-01-01 to the specified date. 88 92 double dateToDaysFrom1970(int year, int month, int day); 89 93 int msToYear(double ms); 94 double msToDays(double ms); 95 int msToMinutes(double ms); 96 int msToHours(double ms); 90 97 int dayInYear(double ms, int year); 91 98 int monthFromDayInYear(int dayInYear, bool leapYear); … … 98 105 } // namespace WTF 99 106 100 using WTF:: adoptArrayPtr;107 using WTF::isLeapYear; 101 108 using WTF::dateToDaysFrom1970; 102 109 using WTF::dayInMonthFromDayInYear; … … 108 115 using WTF::msPerSecond; 109 116 using WTF::msToYear; 117 using WTF::msToDays; 118 using WTF::msToMinutes; 119 using WTF::msToHours; 110 120 using WTF::secondsPerMinute; 111 121 using WTF::parseDateFromNullTerminatedCharacters; … … 114 124 using WTF::calculateDSTOffset; 115 125 116 #if USE(JSC)117 namespace JSC {118 class ExecState;119 struct GregorianDateTime;120 121 void msToGregorianDateTime(ExecState*, double, bool outputIsUTC, GregorianDateTime&);122 double gregorianDateTimeToMS(ExecState*, const GregorianDateTime&, double, bool inputIsUTC);123 double getUTCOffset(ExecState*);124 double parseDateFromNullTerminatedCharacters(ExecState*, const char* dateString);125 126 // Intentionally overridding the default tm of the system.127 // The members of tm differ on various operating systems.128 struct GregorianDateTime {129 WTF_MAKE_NONCOPYABLE(GregorianDateTime);130 public:131 GregorianDateTime()132 : second(0)133 , minute(0)134 , hour(0)135 , weekDay(0)136 , monthDay(0)137 , yearDay(0)138 , month(0)139 , year(0)140 , isDST(0)141 , utcOffset(0)142 {143 }144 145 GregorianDateTime(ExecState* exec, const tm& inTm)146 : second(inTm.tm_sec)147 , minute(inTm.tm_min)148 , hour(inTm.tm_hour)149 , weekDay(inTm.tm_wday)150 , monthDay(inTm.tm_mday)151 , yearDay(inTm.tm_yday)152 , month(inTm.tm_mon)153 , year(inTm.tm_year)154 , isDST(inTm.tm_isdst)155 {156 UNUSED_PARAM(exec);157 #if HAVE(TM_GMTOFF)158 utcOffset = static_cast<int>(inTm.tm_gmtoff);159 #else160 utcOffset = static_cast<int>(getUTCOffset(exec) / WTF::msPerSecond + (isDST ? WTF::secondsPerHour : 0));161 #endif162 163 #if HAVE(TM_ZONE)164 int inZoneSize = strlen(inTm.tm_zone) + 1;165 timeZone = adoptArrayPtr(new char[inZoneSize]);166 strncpy(timeZone.get(), inTm.tm_zone, inZoneSize);167 #else168 timeZone = nullptr;169 #endif170 }171 172 operator tm() const173 {174 tm ret;175 memset(&ret, 0, sizeof(ret));176 177 ret.tm_sec = second;178 ret.tm_min = minute;179 ret.tm_hour = hour;180 ret.tm_wday = weekDay;181 ret.tm_mday = monthDay;182 ret.tm_yday = yearDay;183 ret.tm_mon = month;184 ret.tm_year = year;185 ret.tm_isdst = isDST;186 187 #if HAVE(TM_GMTOFF)188 ret.tm_gmtoff = static_cast<long>(utcOffset);189 #endif190 #if HAVE(TM_ZONE)191 ret.tm_zone = timeZone.get();192 #endif193 194 return ret;195 }196 197 void copyFrom(const GregorianDateTime& rhs)198 {199 second = rhs.second;200 minute = rhs.minute;201 hour = rhs.hour;202 weekDay = rhs.weekDay;203 monthDay = rhs.monthDay;204 yearDay = rhs.yearDay;205 month = rhs.month;206 year = rhs.year;207 isDST = rhs.isDST;208 utcOffset = rhs.utcOffset;209 if (rhs.timeZone) {210 int inZoneSize = strlen(rhs.timeZone.get()) + 1;211 timeZone = adoptArrayPtr(new char[inZoneSize]);212 strncpy(timeZone.get(), rhs.timeZone.get(), inZoneSize);213 } else214 timeZone = nullptr;215 }216 217 int second;218 int minute;219 int hour;220 int weekDay;221 int monthDay;222 int yearDay;223 int month;224 int year;225 int isDST;226 int utcOffset;227 OwnArrayPtr<char> timeZone;228 };229 230 static inline int gmtoffset(const GregorianDateTime& t)231 {232 return t.utcOffset;233 }234 } // namespace JSC235 #endif // USE(JSC)236 237 126 #endif // DateMath_h
Note: See TracChangeset
for help on using the changeset viewer.