Changeset 2612 in webkit for trunk/JavaScriptCore/kjs/date_object.cpp
- Timestamp:
- Nov 8, 2002, 11:46:17 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/date_object.cpp
r2596 r2612 65 65 #include <CoreFoundation/CoreFoundation.h> 66 66 67 #define ctime(x) ctimeUsingCF(x) 67 68 #define gmtime(x) gmtimeUsingCF(x) 68 69 #define localtime(x) localtimeUsingCF(x) 69 70 #define mktime(x) mktimeUsingCF(x) 70 71 struct tm *tmUsingCF(time_t tv, CFTimeZoneRef timeZone) 71 //#define strftime(a, b, c, d) notAllowedToCall() 72 73 struct tm *tmUsingCF(time_t clock, CFTimeZoneRef timeZone) 72 74 { 73 75 static struct tm result; 74 76 static char timeZoneCString[128]; 75 77 76 CFAbsoluteTime absoluteTime = tv - kCFAbsoluteTimeIntervalSince1970; 77 78 CFAbsoluteTime absoluteTime = clock - kCFAbsoluteTimeIntervalSince1970; 78 79 CFGregorianDate date = CFAbsoluteTimeGetGregorianDate(absoluteTime, timeZone); 79 80 80 81 CFStringRef abbreviation = CFTimeZoneCopyAbbreviation(timeZone, absoluteTime); 81 82 82 CFStringGetCString(abbreviation, timeZoneCString, sizeof(timeZoneCString), kCFStringEncodingASCII); 83 CFRelease(abbreviation); 83 84 84 85 result.tm_sec = (int)date.second; … … 94 95 result.tm_zone = timeZoneCString; 95 96 96 CFRelease(abbreviation); 97 return &result; 98 } 99 100 char *ctimeUsingCF(const time_t *clock) 101 { 102 static char result[26]; 97 103 98 return &result; 99 } 100 101 struct tm *gmtimeUsingCF(const time_t *tv) 104 CFTimeZoneRef timeZone = CFTimeZoneCopyDefault(); 105 106 CFAbsoluteTime absoluteTime = *clock - kCFAbsoluteTimeIntervalSince1970; 107 CFGregorianDate date = CFAbsoluteTimeGetGregorianDate(absoluteTime, timeZone); 108 109 const char * const weekdayName[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" }; 110 const char * const monthName[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; 111 112 sprintf(result, "%s %s %02d %02d:%02d:%02.f %04ld\n", 113 weekdayName[CFAbsoluteTimeGetDayOfWeek(absoluteTime, timeZone) - 1], 114 monthName[date.month - 1], date.day, date.hour, date.minute, date.second, date.year); 115 116 CFRelease(timeZone); 117 118 return result; 119 } 120 121 struct tm *gmtimeUsingCF(const time_t *clock) 102 122 { 103 123 static CFTimeZoneRef timeZoneUTC = CFTimeZoneCreateWithName(NULL, CFSTR("UTC"), TRUE); 104 return tmUsingCF(* tv, timeZoneUTC);105 } 106 107 struct tm *localtimeUsingCF(const time_t * tv)124 return tmUsingCF(*clock, timeZoneUTC); 125 } 126 127 struct tm *localtimeUsingCF(const time_t *clock) 108 128 { 109 129 CFTimeZoneRef timeZone = CFTimeZoneCopyDefault(); 110 struct tm *result = tmUsingCF(* tv, timeZone);130 struct tm *result = tmUsingCF(*clock, timeZone); 111 131 CFRelease(timeZone); 112 132 return result; … … 130 150 131 151 return (time_t)(absoluteTime + kCFAbsoluteTimeIntervalSince1970); 152 } 153 154 time_t timeUsingCF(time_t *clock) 155 { 156 time_t result = (time_t)(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970); 157 if (clock) { 158 *clock = result; 159 } 160 return result; 132 161 } 133 162
Note:
See TracChangeset
for help on using the changeset viewer.