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 moved

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/DateMath.cpp

    r44501 r44508  
    22 * Copyright (C) 1999-2000 Harri Porten ([email protected])
    33 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
    4  *
     4 * Copyright (C) 2009 Google Inc. All rights reserved.
     5 *
    56 * The Original Code is Mozilla Communicator client code, released
    67 * March 31, 1998.
     
    4344#include "DateMath.h"
    4445
    45 #include "JSNumberCell.h"
    46 #include <math.h>
     46#include "Assertions.h"
     47#include "ASCIICType.h"
     48#include "CurrentTime.h"
     49#include "MathExtras.h"
     50#include "StringExtras.h"
     51
     52#include <limits>
    4753#include <stdint.h>
    4854#include <time.h>
    49 #include <wtf/ASCIICType.h>
    50 #include <wtf/Assertions.h>
    51 #include <wtf/CurrentTime.h>
    52 #include <wtf/MathExtras.h>
    53 #include <wtf/StringExtras.h>
     55
    5456
    5557#if HAVE(ERRNO_H)
     
    6971#endif
    7072
    71 using namespace WTF;
    72 
    73 namespace JSC {
     73#define NaN std::numeric_limits<double>::quiet_NaN()
     74
     75namespace WTF {
    7476
    7577/* Constants */
     
    497499}
    498500
    499 void initDateMath()
     501void initializeDates()
    500502{
    501503#ifndef NDEBUG
     
    593595}
    594596
    595 double parseDate(const UString &date)
     597double parseDateFromNullTerminatedCharacters(const char* dateString)
    596598{
    597599    // This parses a date in the form:
     
    608610    //
    609611    // We ignore the weekday.
    610 
    611     CString dateCString = date.UTF8String();
    612     const char *dateString = dateCString.c_str();
    613612     
    614613    // Skip leading space
     
    716715            return NaN;
    717716    }
    718    
     717
    719718    // Don't fail if the time is missing.
    720719    long hour = 0;
     
    773772                    return NaN;
    774773                dateString = newPosStr;
    775            
     774
    776775                if (second < 0 || second > 59)
    777776                    return NaN;
     
    849848        dateString = newPosStr;
    850849    }
    851      
     850
    852851    skipSpacesAndComments(dateString);
    853      
     852
    854853    // Trailing garbage
    855854    if (*dateString)
     
    891890}
    892891
    893 UString formatDate(const GregorianDateTime &t)
    894 {
    895     char buffer[100];
    896     snprintf(buffer, sizeof(buffer), "%s %s %02d %04d",
    897         weekdayName[(t.weekDay + 6) % 7],
    898         monthName[t.month], t.monthDay, t.year + 1900);
    899     return buffer;
    900 }
    901 
    902 UString formatDateUTCVariant(const GregorianDateTime &t)
    903 {
    904     char buffer[100];
    905     snprintf(buffer, sizeof(buffer), "%s, %02d %s %04d",
    906         weekdayName[(t.weekDay + 6) % 7],
    907         t.monthDay, monthName[t.month], t.year + 1900);
    908     return buffer;
    909 }
    910 
    911 UString formatTime(const GregorianDateTime &t, bool utc)
    912 {
    913     char buffer[100];
    914     if (utc) {
    915         snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d GMT", t.hour, t.minute, t.second);
    916     } else {
    917         int offset = abs(gmtoffset(t));
    918         char timeZoneName[70];
    919         struct tm gtm = t;
    920         strftime(timeZoneName, sizeof(timeZoneName), "%Z", &gtm);
    921 
    922         if (timeZoneName[0]) {
    923             snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d GMT%c%02d%02d (%s)",
    924                 t.hour, t.minute, t.second,
    925                 gmtoffset(t) < 0 ? '-' : '+', offset / (60*60), (offset / 60) % 60, timeZoneName);
    926         } else {
    927             snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d GMT%c%02d%02d",
    928                 t.hour, t.minute, t.second,
    929                 gmtoffset(t) < 0 ? '-' : '+', offset / (60*60), (offset / 60) % 60);
    930         }
    931     }
    932     return UString(buffer);
    933 }
    934 
    935 } // namespace JSC
     892
     893} // namespace WTF
Note: See TracChangeset for help on using the changeset viewer.