Changeset 3177 in webkit for trunk/JavaScriptCore/kjs/date_object.cpp
- Timestamp:
- Dec 23, 2002, 2:35:52 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/date_object.cpp
r3098 r3177 74 74 #define localtime(x) localtimeUsingCF(x) 75 75 #define mktime(x) mktimeUsingCF(x) 76 #define timegm(x) timegmUsingCF(x) 76 77 #define time(x) timeUsingCF(x) 77 78 … … 123 124 } 124 125 125 static time_t mktimeUsingCF(struct tm *tm)126 static time_t timetUsingCF(struct tm *tm, CFTimeZoneRef timeZone) 126 127 { 127 128 CFGregorianDate date; … … 135 136 // CFGregorianDateGetAbsoluteTime will go nuts if the year is too large, 136 137 // so we pick an arbitrary cutoff. 137 if ( !CFGregorianDateIsValid(date, kCFGregorianAllUnits) ||date.year > 2500) {138 if (date.year > 2500) { 138 139 return invalidDate; 139 140 } 140 141 142 CFAbsoluteTime absoluteTime = CFGregorianDateGetAbsoluteTime(date, timeZone); 143 144 return (time_t)(absoluteTime + kCFAbsoluteTimeIntervalSince1970); 145 } 146 147 static time_t mktimeUsingCF(struct tm *tm) 148 { 141 149 CFTimeZoneRef timeZone = CFTimeZoneCopyDefault(); 142 CFAbsoluteTime absoluteTime = CFGregorianDateGetAbsoluteTime(date, timeZone);150 time_t result = timetUsingCF(tm, timeZone); 143 151 CFRelease(timeZone); 144 145 return (time_t)(absoluteTime + kCFAbsoluteTimeIntervalSince1970); 152 return result; 153 } 154 155 static time_t timegmUsingCF(struct tm *tm) 156 { 157 static CFTimeZoneRef timeZoneUTC = CFTimeZoneCreateWithName(NULL, CFSTR("UTC"), TRUE); 158 return timetUsingCF(tm, timeZoneUTC); 146 159 } 147 160 … … 155 168 } 156 169 157 static UString formatDate(struct tm &tm , bool includeComma = false)170 static UString formatDate(struct tm &tm) 158 171 { 159 172 char buffer[100]; 160 snprintf(buffer, sizeof(buffer), "%s %s%s %02d %04d",161 weekdayName[(tm.tm_wday + 6) % 7], includeComma ? "," : "",173 snprintf(buffer, sizeof(buffer), "%s %s %02d %04d", 174 weekdayName[(tm.tm_wday + 6) % 7], 162 175 monthName[tm.tm_mon], tm.tm_mday, tm.tm_year + 1900); 176 return buffer; 177 } 178 179 static UString formatDateUTCVariant(struct tm &tm) 180 { 181 char buffer[100]; 182 snprintf(buffer, sizeof(buffer), "%s, %02d %s %04d", 183 weekdayName[(tm.tm_wday + 6) % 7], 184 tm.tm_mday, monthName[tm.tm_mon], tm.tm_year + 1900); 163 185 return buffer; 164 186 } … … 377 399 case ToGMTString: 378 400 case ToUTCString: 379 result = String(formatDate (*t, true) + " " + formatTime(*t));401 result = String(formatDateUTCVariant(*t) + " " + formatTime(*t)); 380 402 break; 381 403 case ToLocaleString: … … 532 554 putDirect(parsePropertyName, new DateObjectFuncImp(exec,funcProto,DateObjectFuncImp::Parse, 1), DontEnum); 533 555 static const Identifier UTCPropertyName("UTC"); 534 putDirect( "UTC", new DateObjectFuncImp(exec,funcProto,DateObjectFuncImp::UTC, 7), DontEnum);556 putDirect(UTCPropertyName, new DateObjectFuncImp(exec,funcProto,DateObjectFuncImp::UTC, 7), DontEnum); 535 557 536 558 // no. of arguments for constructor … … 595 617 t.tm_min = (numArgs >= 5) ? args[4].toInt32(exec) : 0; 596 618 t.tm_sec = (numArgs >= 6) ? args[5].toInt32(exec) : 0; 597 t.tm_isdst = invalidDate;619 t.tm_isdst = -1; 598 620 int ms = (numArgs >= 7) ? args[6].toInt32(exec) : 0; 599 621 time_t mktimeResult = mktime(&t); … … 679 701 t.tm_sec = (n >= 6) ? args[5].toInt32(exec) : 0; 680 702 int ms = (n >= 7) ? args[6].toInt32(exec) : 0; 681 time_t mktimeResult = mktime(&t);703 time_t mktimeResult = timegm(&t); 682 704 if (mktimeResult == invalidDate) 683 705 return Number(NaN);
Note:
See TracChangeset
for help on using the changeset viewer.