Commit f3f2e131 authored by paroga@webkit.org's avatar paroga@webkit.org

Replace WTF::getCurrentLocalTime() with GregorianDateTime::setToCurrentLocalTime()

https://bugs.webkit.org/show_bug.cgi?id=92286

Reviewed by Geoffrey Garen.

Add a method to GregorianDateTime to set its values to the current locale time.
Replacing all occurrences of getCurrentLocalTime with the new function allows
us to remove getCurrentLocalTime in a next step.

Source/JavaScriptCore:

* JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:

Source/WebCore:

* html/FTPDirectoryDocument.cpp:
(WebCore::processFileDateString):
* loader/archive/mhtml/MHTMLArchive.cpp:
(WebCore::MHTMLArchive::generateMHTMLData):

Source/WTF:

* GNUmakefile.list.am:
* WTF.gypi:
* WTF.pro:
* WTF.vcproj/WTF.vcproj:
* WTF.xcodeproj/project.pbxproj:
* wtf/CMakeLists.txt:
* wtf/DateMath.cpp:
(WTF::dayInYear):
* wtf/DateMath.h:
(WTF):
* wtf/GregorianDateTime.cpp: Added.
(WTF):
(WTF::GregorianDateTime::setToCurrentLocalTime):
* wtf/GregorianDateTime.h:
(GregorianDateTime):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@124365 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent df7dab83
2012-08-01 Patrick Gansterer <paroga@webkit.org>
Replace WTF::getCurrentLocalTime() with GregorianDateTime::setToCurrentLocalTime()
https://bugs.webkit.org/show_bug.cgi?id=92286
Reviewed by Geoffrey Garen.
Add a method to GregorianDateTime to set its values to the current locale time.
Replacing all occurrences of getCurrentLocalTime with the new function allows
us to remove getCurrentLocalTime in a next step.
* JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
2012-08-01 Mark Hahnenberg <mhahnenberg@apple.com>
C++ code should get ClassInfo from the Structure
......
......@@ -315,6 +315,7 @@ EXPORTS
?setOrderLowerFirst@Collator@WTF@@QAEX_N@Z
?setPrototype@JSObject@JSC@@QAEXAAVJSGlobalData@2@VJSValue@2@@Z
?setSetter@PropertyDescriptor@JSC@@QAEXVJSValue@2@@Z
?setToCurrentLocalTime@GregorianDateTime@WTF@@QAEXXZ
?setUndefined@PropertyDescriptor@JSC@@QAEXXZ
?setUnwrappedObject@JSGlobalThis@JSC@@IAEXAAVJSGlobalData@2@PAVJSGlobalObject@2@@Z
?setUpStaticFunctionSlot@JSC@@YA_NPAVExecState@1@PBVHashEntry@1@PAVJSObject@1@VPropertyName@1@AAVPropertySlot@1@@Z
......
2012-08-01 Patrick Gansterer <paroga@webkit.org>
Replace WTF::getCurrentLocalTime() with GregorianDateTime::setToCurrentLocalTime()
https://bugs.webkit.org/show_bug.cgi?id=92286
Reviewed by Geoffrey Garen.
Add a method to GregorianDateTime to set its values to the current locale time.
Replacing all occurrences of getCurrentLocalTime with the new function allows
us to remove getCurrentLocalTime in a next step.
* GNUmakefile.list.am:
* WTF.gypi:
* WTF.pro:
* WTF.vcproj/WTF.vcproj:
* WTF.xcodeproj/project.pbxproj:
* wtf/CMakeLists.txt:
* wtf/DateMath.cpp:
(WTF::dayInYear):
* wtf/DateMath.h:
(WTF):
* wtf/GregorianDateTime.cpp: Added.
(WTF):
(WTF::GregorianDateTime::setToCurrentLocalTime):
* wtf/GregorianDateTime.h:
(GregorianDateTime):
2012-08-01 Patrick Gansterer <paroga@webkit.org>
Fix FastMalloc build with assertions enabled.
......
......@@ -52,6 +52,7 @@ wtf_sources += \
Source/WTF/wtf/Forward.h \
Source/WTF/wtf/Functional.h \
Source/WTF/wtf/GetPtr.h \
Source/WTF/wtf/GregorianDateTime.cpp \
Source/WTF/wtf/GregorianDateTime.h \
Source/WTF/wtf/HashCountedSet.h \
Source/WTF/wtf/HashFunctions.h \
......
......@@ -144,6 +144,7 @@
'wtf/FastMalloc.cpp',
'wtf/Float32Array.h',
'wtf/Float64Array.h',
'wtf/GregorianDateTime.cpp',
'wtf/HashTable.cpp',
'wtf/Int16Array.h',
'wtf/Int32Array.h',
......
......@@ -190,6 +190,7 @@ SOURCES += \
dtoa/fixed-dtoa.cc \
dtoa/strtod.cc \
FastMalloc.cpp \
GregorianDateTime.cpp \
gobject/GOwnPtr.cpp \
gobject/GRefPtr.cpp \
HashTable.cpp \
......
......@@ -796,6 +796,10 @@
RelativePath="..\wtf\GetPtr.h"
>
</File>
<File
RelativePath="..\wtf\GregorianDateTime.cpp"
>
</File>
<File
RelativePath="..\wtf\GregorianDateTime.h"
>
......
......@@ -11,6 +11,7 @@
143F611F1565F0F900DB514A /* RAMSize.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 143F611D1565F0F900DB514A /* RAMSize.cpp */; };
143F61201565F0F900DB514A /* RAMSize.h in Headers */ = {isa = PBXBuildFile; fileRef = 143F611E1565F0F900DB514A /* RAMSize.h */; settings = {ATTRIBUTES = (Private, ); }; };
2C05385415BC819000F21B96 /* GregorianDateTime.h in Headers */ = {isa = PBXBuildFile; fileRef = 2C05385315BC819000F21B96 /* GregorianDateTime.h */; };
2CCD892A15C0390200285083 /* GregorianDateTime.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2CCD892915C0390200285083 /* GregorianDateTime.cpp */; };
4330F38F15745B0500AAFA8F /* URLString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4330F38E15745B0500AAFA8F /* URLString.cpp */; };
4F0321BC156AA8D1006EBAF6 /* BitArray.h in Headers */ = {isa = PBXBuildFile; fileRef = 4F0321BB156AA8D1006EBAF6 /* BitArray.h */; };
8134013815B092FD001FF0B8 /* Base64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8134013615B092FD001FF0B8 /* Base64.cpp */; };
......@@ -254,6 +255,7 @@
143F611D1565F0F900DB514A /* RAMSize.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RAMSize.cpp; sourceTree = "<group>"; };
143F611E1565F0F900DB514A /* RAMSize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RAMSize.h; sourceTree = "<group>"; };
2C05385315BC819000F21B96 /* GregorianDateTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GregorianDateTime.h; sourceTree = "<group>"; };
2CCD892915C0390200285083 /* GregorianDateTime.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GregorianDateTime.cpp; sourceTree = "<group>"; };
4330F38E15745B0500AAFA8F /* URLString.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = URLString.cpp; sourceTree = "<group>"; };
4F0321BB156AA8D1006EBAF6 /* BitArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BitArray.h; sourceTree = "<group>"; };
5D247B6214689B8600E78B76 /* libWTF.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libWTF.a; sourceTree = BUILT_PRODUCTS_DIR; };
......@@ -614,6 +616,7 @@
A8A472A6151A825A004123FF /* Forward.h */,
A8A472A7151A825A004123FF /* Functional.h */,
A8A472A8151A825A004123FF /* GetPtr.h */,
2CCD892915C0390200285083 /* GregorianDateTime.cpp */,
2C05385315BC819000F21B96 /* GregorianDateTime.h */,
A8A472B3151A825A004123FF /* HashCountedSet.h */,
A8A472B4151A825A004123FF /* HashFunctions.h */,
......@@ -1172,6 +1175,7 @@
A8A473B3151A825B004123FF /* fast-dtoa.cc in Sources */,
A8A473C3151A825B004123FF /* FastMalloc.cpp in Sources */,
A8A473B5151A825B004123FF /* fixed-dtoa.cc in Sources */,
2CCD892A15C0390200285083 /* GregorianDateTime.cpp in Sources */,
A8A473D8151A825B004123FF /* HashTable.cpp in Sources */,
A8A473E5151A825B004123FF /* MainThread.cpp in Sources */,
A8A473E4151A825B004123FF /* MainThreadMac.mm in Sources */,
......
......@@ -147,6 +147,7 @@ SET(WTF_SOURCES
DecimalNumber.cpp
DynamicAnnotations.cpp
FastMalloc.cpp
GregorianDateTime.cpp
HashTable.cpp
MD5.cpp
MainThread.cpp
......
......@@ -286,7 +286,7 @@ int dayInMonthFromDayInYear(int dayInYear, bool leapYear)
return d - step;
}
static inline int dayInYear(int year, int month, int day)
int dayInYear(int year, int month, int day)
{
return firstDayOfMonth[isLeapYear(year)][month] + day - 1;
}
......
......@@ -95,6 +95,7 @@ WTF_EXPORT_PRIVATE int msToYear(double ms);
double msToDays(double ms);
int msToMinutes(double ms);
int msToHours(double ms);
int dayInYear(int year, int month, int day);
WTF_EXPORT_PRIVATE int dayInYear(double ms, int year);
WTF_EXPORT_PRIVATE int monthFromDayInYear(int dayInYear, bool leapYear);
WTF_EXPORT_PRIVATE int dayInMonthFromDayInYear(int dayInYear, bool leapYear);
......
/*
* Copyright (C) 2012 Patrick Gansterer <paroga@paroga.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "GregorianDateTime.h"
#include "DateMath.h"
#if OS(WINDOWS)
#include <windows.h>
#else
#include <time.h>
#endif
namespace WTF {
void GregorianDateTime::setToCurrentLocalTime()
{
#if OS(WINDOWS)
SYSTEMTIME systemTime;
GetLocalTime(&systemTime);
TIME_ZONE_INFORMATION timeZoneInformation;
DWORD timeZoneId = GetTimeZoneInformation(&timeZoneInformation);
LONG bias = timeZoneInformation.Bias;
if (timeZoneId == TIME_ZONE_ID_DAYLIGHT)
bias += timeZoneInformation.DaylightBias;
else if (timeZoneId == TIME_ZONE_ID_STANDARD)
bias += timeZoneInformation.StandardBias;
else
ASSERT(timeZoneId == TIME_ZONE_ID_UNKNOWN);
m_year = systemTime.wYear;
m_month = systemTime.wMonth - 1;
m_monthDay = systemTime.wDay;
m_yearDay = dayInYear(m_year, m_month, m_monthDay);
m_weekDay = systemTime.wDayOfWeek;
m_hour = systemTime.wHour;
m_minute = systemTime.wMinute;
m_second = systemTime.wSecond;
m_utcOffset = -bias * secondsPerMinute;
m_isDST = timeZoneId == TIME_ZONE_ID_DAYLIGHT ? 1 : 0;
#else
tm localTM;
time_t localTime = time(0);
localtime_r(&localTime, &localTM);
m_year = localTM.tm_year + 1900;
m_month = localTM.tm_mon;
m_monthDay = localTM.tm_mday;
m_yearDay = localTM.tm_yday;
m_weekDay = localTM.tm_wday;
m_hour = localTM.tm_hour;
m_minute = localTM.tm_min;
m_second = localTM.tm_sec;
m_isDST = localTM.tm_isdst;
#if HAVE(TM_GMTOFF)
m_utcOffset = localTM.tm_gmtoff;
#else
int utcOffset = calculateUTCOffset();
utcOffset += calculateDSTOffset(localTime * msPerSecond, utcOffset);
m_utcOffset = utcOffset / msPerSecond;
#endif
#endif
}
} // namespace WTF
......@@ -70,6 +70,8 @@ public:
inline void setUtcOffset(int utcOffset) { m_utcOffset = utcOffset; }
inline void setIsDST(int isDST) { m_isDST = isDST; }
WTF_EXPORT_PRIVATE void setToCurrentLocalTime();
operator tm() const
{
tm ret;
......
2012-08-01 Patrick Gansterer <paroga@webkit.org>
Replace WTF::getCurrentLocalTime() with GregorianDateTime::setToCurrentLocalTime()
https://bugs.webkit.org/show_bug.cgi?id=92286
Reviewed by Geoffrey Garen.
Add a method to GregorianDateTime to set its values to the current locale time.
Replacing all occurrences of getCurrentLocalTime with the new function allows
us to remove getCurrentLocalTime in a next step.
* html/FTPDirectoryDocument.cpp:
(WebCore::processFileDateString):
* loader/archive/mhtml/MHTMLArchive.cpp:
(WebCore::MHTMLArchive::generateMHTMLData):
2012-08-01 Ojan Vafai <ojan@chromium.org>
Remove code duplication in determining if display is inline or replaced
......@@ -36,10 +36,11 @@
#include "Settings.h"
#include "SharedBuffer.h"
#include "Text.h"
#include <wtf/text/CString.h>
#include <wtf/text/WTFString.h>
#include <wtf/CurrentTime.h>
#include <wtf/GregorianDateTime.h>
#include <wtf/StdLibExtras.h>
#include <wtf/text/CString.h>
#include <wtf/text/WTFString.h>
#include <wtf/unicode/CharacterNames.h>
using namespace std;
......@@ -219,26 +220,23 @@ static String processFileDateString(const FTPTime& fileTime)
}
// If it was today or yesterday, lets just do that - but we have to compare to the current time
struct tm now;
getCurrentLocalTime(&now);
// localtime does "year = current year - 1900", compensate for that for readability and comparison purposes
now.tm_year += 1900;
GregorianDateTime now;
now.setToCurrentLocalTime();
if (fileTime.tm_year == now.tm_year) {
if (fileTime.tm_mon == now.tm_mon) {
if (fileTime.tm_mday == now.tm_mday)
if (fileTime.tm_year == now.year()) {
if (fileTime.tm_mon == now.month()) {
if (fileTime.tm_mday == now.monthDay())
return "Today" + timeOfDay;
if (fileTime.tm_mday == now.tm_mday - 1)
if (fileTime.tm_mday == now.monthDay() - 1)
return "Yesterday" + timeOfDay;
}
if (now.tm_mday == 1 && (now.tm_mon == fileTime.tm_mon + 1 || (now.tm_mon == 0 && fileTime.tm_mon == 11)) &&
if (now.monthDay() == 1 && (now.month() == fileTime.tm_mon + 1 || (now.month() == 0 && fileTime.tm_mon == 11)) &&
wasLastDayOfMonth(fileTime.tm_year, fileTime.tm_mon, fileTime.tm_mday))
return "Yesterday" + timeOfDay;
}
if (fileTime.tm_year == now.tm_year - 1 && fileTime.tm_mon == 12 && fileTime.tm_mday == 31 && now.tm_mon == 1 && now.tm_mday == 1)
if (fileTime.tm_year == now.year() - 1 && fileTime.tm_mon == 12 && fileTime.tm_mday == 31 && now.month() == 1 && now.monthDay() == 1)
return "Yesterday" + timeOfDay;
static const char* months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???" };
......@@ -252,7 +250,7 @@ static String processFileDateString(const FTPTime& fileTime)
if (fileTime.tm_year > -1)
dateString = String(months[month]) + " " + String::number(fileTime.tm_mday) + ", " + String::number(fileTime.tm_year);
else
dateString = String(months[month]) + " " + String::number(fileTime.tm_mday) + ", " + String::number(now.tm_year);
dateString = String(months[month]) + " " + String::number(fileTime.tm_mday) + ", " + String::number(now.year());
return dateString + timeOfDay;
}
......
......@@ -45,6 +45,7 @@
#include <wtf/CryptographicallyRandomNumber.h>
#include <wtf/DateMath.h>
#include <wtf/GregorianDateTime.h>
#include <wtf/StdLibExtras.h>
#include <wtf/text/Base64.h>
#include <wtf/text/StringBuilder.h>
......@@ -150,9 +151,9 @@ PassRefPtr<SharedBuffer> MHTMLArchive::generateMHTMLData(Page* page, bool useBin
String boundary = generateRandomBoundary();
String endOfResourceBoundary = makeString("--", boundary, "\r\n");
tm localTM;
getCurrentLocalTime(&localTM);
String dateString = makeRFC2822DateString(localTM.tm_wday, localTM.tm_mday, localTM.tm_mon, 1900 + localTM.tm_year, localTM.tm_hour, localTM.tm_min, localTM.tm_sec, calculateUTCOffset() / (1000 * 60));
GregorianDateTime now;
now.setToCurrentLocalTime();
String dateString = makeRFC2822DateString(now.weekDay(), now.monthDay(), now.month(), now.year(), now.hour(), now.minute(), now.second(), now.utcOffset() / 60);
StringBuilder stringBuilder;
stringBuilder.append("From: <Saved by WebKit>\r\n");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment