Ignore:
Timestamp:
Jun 8, 2009, 3:37:06 PM (16 years ago)
Author:
Dimitri Glazkov
Message:

JavaScriptCore:

2009-06-08 Dimitri Glazkov <Dimitri Glazkov>

Reviewed by Eric Seidel.

https://bugs.webkit.org/show_bug.cgi?id=26238
Move most of runtime/DateMath functions to wtf/DateMath, and split off conversion-related
helpers to DateConversion.

  • AllInOneFile.cpp: Changed DateMath->DateConversion.
  • GNUmakefile.am: Ditto and added DateMath.
  • JavaScriptCore.exp: Ditto.
  • JavaScriptCore.pri: Ditto.
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj: Ditto.
  • JavaScriptCore.vcproj/WTF/WTF.vcproj: Added DateMath.
  • JavaScriptCore.xcodeproj/project.pbxproj: Ditto.
  • JavaScriptCoreSources.bkl: Ditto.
  • pcre/pcre_exec.cpp: Changed to use DateMath.
  • profiler/ProfileNode.cpp: (JSC::getCount): Changed to use DateConversion.
  • runtime/DateConstructor.cpp: Ditto.
  • runtime/DateConversion.cpp: Copied from JavaScriptCore/runtime/DateMath.cpp. (JSC::parseDate): Refactored to use null-terminated characters as input.
  • runtime/DateConversion.h: Copied from JavaScriptCore/runtime/DateMath.h.
  • runtime/DateInstance.cpp: Changed to use wtf/DateMath.
  • runtime/DateInstance.h: Ditto.
  • runtime/DateMath.cpp: Removed.
  • runtime/DateMath.h: Removed.
  • runtime/DatePrototype.cpp: Ditto.
  • runtime/InitializeThreading.cpp: Ditto.
  • wtf/DateMath.cpp: Copied from JavaScriptCore/runtime/DateMath.cpp.
  • wtf/DateMath.h: Copied from JavaScriptCore/runtime/DateMath.h.

WebCore:

2009-06-08 Dimitri Glazkov <Dimitri Glazkov>

Reviewed by Eric Seidel.

https://bugs.webkit.org/show_bug.cgi?id=26238
Add parseDate helper to HTTPParsers, which uses WTF::parseDateFromNullTerminatedCharacters.

  • ForwardingHeaders/runtime/DateMath.h: Removed.
  • ForwardingHeaders/wtf/DateMath.h: Copied from WebCore/ForwardingHeaders/runtime/DateMath.h.
  • platform/network/HTTPParsers.cpp: (WebCore::parseDate): Added.
  • platform/network/HTTPParsers.h:
  • platform/network/ResourceResponseBase.cpp: (WebCore::parseDateValueInHeader): Changed to use the new helper.
File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/DateConversion.h

    r44501 r44508  
    22 * Copyright (C) 1999-2000 Harri Porten ([email protected])
    33 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
     4 * Copyright (C) 2009 Google Inc. All rights reserved.
    45 *
    56 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
     
    3940 */
    4041
    41 #ifndef DateMath_h
    42 #define DateMath_h
     42#ifndef DateConversion_h
     43#define DateConversion_h
    4344
    44 #include <time.h>
    45 #include <string.h>
    46 #include <wtf/Noncopyable.h>
     45namespace WTF {
     46    struct GregorianDateTime;
     47}
    4748
    4849namespace JSC {
    4950
    5051class UString;
    51 struct GregorianDateTime;
    5252
    53 void initDateMath();
    54 void msToGregorianDateTime(double, bool outputIsUTC, GregorianDateTime&);
    55 double gregorianDateTimeToMS(const GregorianDateTime&, double, bool inputIsUTC);
    56 double getUTCOffset();
    57 int equivalentYearForDST(int year);
    58 double getCurrentUTCTime();
    59 double getCurrentUTCTimeWithMicroseconds();
    60 void getLocalTime(const time_t*, tm*);
    61 
    62 // Not really math related, but this is currently the only shared place to put these. 
    6353double parseDate(const UString&);
    64 double timeClip(double);
    65 UString formatDate(const GregorianDateTime&);
    66 UString formatDateUTCVariant(const GregorianDateTime&);
    67 UString formatTime(const GregorianDateTime&, bool inputIsUTC);
    68 
    69 
    70 const char * const weekdayName[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
    71 const char * const monthName[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
    72 
    73 const double hoursPerDay = 24.0;
    74 const double minutesPerHour = 60.0;
    75 const double secondsPerHour = 60.0 * 60.0;
    76 const double secondsPerMinute = 60.0;
    77 const double msPerSecond = 1000.0;
    78 const double msPerMinute = 60.0 * 1000.0;
    79 const double msPerHour = 60.0 * 60.0 * 1000.0;
    80 const double msPerDay = 24.0 * 60.0 * 60.0 * 1000.0;
    81 
    82 // Intentionally overridding the default tm of the system
    83 // Tee members of tm differ on various operating systems.
    84 struct GregorianDateTime : Noncopyable {
    85     GregorianDateTime()
    86         : second(0)
    87         , minute(0)
    88         , hour(0)
    89         , weekDay(0)
    90         , monthDay(0)
    91         , yearDay(0)
    92         , month(0)
    93         , year(0)
    94         , isDST(0)
    95         , utcOffset(0)
    96         , timeZone(0)
    97     {
    98     }
    99 
    100     ~GregorianDateTime()
    101     {
    102         delete [] timeZone;
    103     }
    104 
    105     GregorianDateTime(const tm& inTm)
    106         : second(inTm.tm_sec)
    107         , minute(inTm.tm_min)
    108         , hour(inTm.tm_hour)
    109         , weekDay(inTm.tm_wday)
    110         , monthDay(inTm.tm_mday)
    111         , yearDay(inTm.tm_yday)
    112         , month(inTm.tm_mon)
    113         , year(inTm.tm_year)
    114         , isDST(inTm.tm_isdst)
    115     {
    116 #if !PLATFORM(WIN_OS) && !PLATFORM(SOLARIS) && !COMPILER(RVCT)
    117         utcOffset = static_cast<int>(inTm.tm_gmtoff);
    118 
    119         int inZoneSize = strlen(inTm.tm_zone) + 1;
    120         timeZone = new char[inZoneSize];
    121         strncpy(timeZone, inTm.tm_zone, inZoneSize);
    122 #else
    123         utcOffset = static_cast<int>(getUTCOffset() / msPerSecond + (isDST ? secondsPerHour : 0));
    124         timeZone = 0;
    125 #endif
    126     }
    127 
    128     operator tm() const
    129     {
    130         tm ret;
    131         memset(&ret, 0, sizeof(ret));
    132 
    133         ret.tm_sec   =  second;
    134         ret.tm_min   =  minute;
    135         ret.tm_hour  =  hour;
    136         ret.tm_wday  =  weekDay;
    137         ret.tm_mday  =  monthDay;
    138         ret.tm_yday  =  yearDay;
    139         ret.tm_mon   =  month;
    140         ret.tm_year  =  year;
    141         ret.tm_isdst =  isDST;
    142 
    143 #if !PLATFORM(WIN_OS) && !PLATFORM(SOLARIS) && !COMPILER(RVCT)
    144         ret.tm_gmtoff = static_cast<long>(utcOffset);
    145         ret.tm_zone = timeZone;
    146 #endif
    147 
    148         return ret;
    149     }
    150 
    151     void copyFrom(const GregorianDateTime& rhs)
    152     {
    153         second = rhs.second;
    154         minute = rhs.minute;
    155         hour = rhs.hour;
    156         weekDay = rhs.weekDay;
    157         monthDay = rhs.monthDay;
    158         yearDay = rhs.yearDay;
    159         month = rhs.month;
    160         year = rhs.year;
    161         isDST = rhs.isDST;
    162         utcOffset = rhs.utcOffset;
    163         if (rhs.timeZone) {
    164             int inZoneSize = strlen(rhs.timeZone) + 1;
    165             timeZone = new char[inZoneSize];
    166             strncpy(timeZone, rhs.timeZone, inZoneSize);
    167         } else
    168             timeZone = 0;
    169     }
    170 
    171     int second;
    172     int minute;
    173     int hour;
    174     int weekDay;
    175     int monthDay;
    176     int yearDay;
    177     int month;
    178     int year;
    179     int isDST;
    180     int utcOffset;
    181     char* timeZone;
    182 };
    183 
    184 static inline int gmtoffset(const GregorianDateTime& t)
    185 {
    186     return t.utcOffset;
    187 }
     54UString formatDate(const WTF::GregorianDateTime&);
     55UString formatDateUTCVariant(const WTF::GregorianDateTime&);
     56UString formatTime(const WTF::GregorianDateTime&, bool inputIsUTC);
    18857
    18958} // namespace JSC
    19059
    191 #endif // DateMath_h
     60#endif // DateConversion_h
Note: See TracChangeset for help on using the changeset viewer.