Commit 683889fe authored by paroga@webkit.org's avatar paroga@webkit.org

Store the full year in GregorianDateTime

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

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

Use the full year instead of the offset from year 1900
for the year member variable of GregorianDateTime.

* runtime/DateConstructor.cpp:
(JSC::constructDate):
(JSC::dateUTC):
* runtime/DateConversion.cpp:
(JSC::formatDate):
(JSC::formatDateUTCVariant):
* runtime/DatePrototype.cpp:
(JSC::formatLocaleDate):
(JSC::fillStructuresUsingDateArgs):
(JSC::dateProtoFuncToISOString):
(JSC::dateProtoFuncGetFullYear):
(JSC::dateProtoFuncGetUTCFullYear):
(JSC::dateProtoFuncSetYear):
* runtime/JSDateMath.cpp:
(JSC::gregorianDateTimeToMS):
(JSC::msToGregorianDateTime):

Source/WebCore:

Use the full year instead of the offset from year 1900
for the year member variable of GregorianDateTime.

* bridge/qt/qt_runtime.cpp:
(JSC::Bindings::convertValueToQVariant):
(JSC::Bindings::convertQVariantToValue):
* bridge/qt/qt_runtime_qt4.cpp:
(JSC::Bindings::convertValueToQVariant):
(JSC::Bindings::convertQVariantToValue):

Source/WTF:

Use the full year instead of the offset from year 1900
for the year member variable of GregorianDateTime.

* wtf/GregorianDateTime.h:
(WTF::GregorianDateTime::operator tm):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@123505 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f3271352
2012-07-24 Patrick Gansterer <paroga@webkit.org>
Store the full year in GregorianDateTime
https://bugs.webkit.org/show_bug.cgi?id=92067
Reviewed by Geoffrey Garen.
Use the full year instead of the offset from year 1900
for the year member variable of GregorianDateTime.
* runtime/DateConstructor.cpp:
(JSC::constructDate):
(JSC::dateUTC):
* runtime/DateConversion.cpp:
(JSC::formatDate):
(JSC::formatDateUTCVariant):
* runtime/DatePrototype.cpp:
(JSC::formatLocaleDate):
(JSC::fillStructuresUsingDateArgs):
(JSC::dateProtoFuncToISOString):
(JSC::dateProtoFuncGetFullYear):
(JSC::dateProtoFuncGetUTCFullYear):
(JSC::dateProtoFuncSetYear):
* runtime/JSDateMath.cpp:
(JSC::gregorianDateTimeToMS):
(JSC::msToGregorianDateTime):
2012-07-24 Patrick Gansterer <paroga@webkit.org>
[WIN] Build fix after r123417.
......
......@@ -136,7 +136,7 @@ JSObject* constructDate(ExecState* exec, JSGlobalObject* globalObject, const Arg
else {
GregorianDateTime t;
int year = JSC::toInt32(doubleArguments[0]);
t.setYear((year >= 0 && year <= 99) ? year : year - 1900);
t.setYear((year >= 0 && year <= 99) ? (year + 1900) : year);
t.setMonth(JSC::toInt32(doubleArguments[1]));
t.setMonthDay((numArgs >= 3) ? JSC::toInt32(doubleArguments[2]) : 1);
t.setHour(JSC::toInt32(doubleArguments[3]));
......@@ -214,7 +214,7 @@ static EncodedJSValue JSC_HOST_CALL dateUTC(ExecState* exec)
GregorianDateTime t;
int year = JSC::toInt32(doubleArguments[0]);
t.setYear((year >= 0 && year <= 99) ? year : year - 1900);
t.setYear((year >= 0 && year <= 99) ? (year + 1900) : year);
t.setMonth(JSC::toInt32(doubleArguments[1]));
t.setMonthDay((n >= 3) ? JSC::toInt32(doubleArguments[2]) : 1);
t.setHour(JSC::toInt32(doubleArguments[3]));
......
......@@ -59,14 +59,14 @@ void formatDate(const GregorianDateTime &t, DateConversionBuffer& buffer)
{
snprintf(buffer, DateConversionBufferSize, "%s %s %02d %04d",
weekdayName[(t.weekDay() + 6) % 7],
monthName[t.month()], t.monthDay(), t.year() + 1900);
monthName[t.month()], t.monthDay(), t.year());
}
void formatDateUTCVariant(const GregorianDateTime &t, DateConversionBuffer& buffer)
{
snprintf(buffer, DateConversionBufferSize, "%s, %02d %s %04d",
weekdayName[(t.weekDay() + 6) % 7],
t.monthDay(), monthName[t.month()], t.year() + 1900);
t.monthDay(), monthName[t.month()], t.year());
}
void formatTime(const GregorianDateTime &t, DateConversionBuffer& buffer)
......
......@@ -222,7 +222,7 @@ static JSCell* formatLocaleDate(ExecState* exec, const GregorianDateTime& gdt, L
#if OS(WINDOWS)
SYSTEMTIME systemTime;
memset(&systemTime, 0, sizeof(systemTime));
systemTime.wYear = gdt.year() + 1900;
systemTime.wYear = gdt.year();
systemTime.wMonth = gdt.month() + 1;
systemTime.wDay = gdt.monthDay();
systemTime.wDayOfWeek = gdt.weekDay();
......@@ -265,7 +265,7 @@ static JSCell* formatLocaleDate(ExecState* exec, const GregorianDateTime& gdt, L
// Offset year if needed
struct tm localTM = gdt;
int year = gdt.year() + 1900;
int year = gdt.year();
bool yearNeedsOffset = year < 1900 || year > 2038;
if (yearNeedsOffset)
localTM.tm_year = equivalentYearForDST(year) - 1900;
......@@ -412,7 +412,7 @@ static bool fillStructuresUsingDateArgs(ExecState *exec, int maxArgs, double *ms
if (maxArgs >= 3 && idx < numArgs) {
double years = exec->argument(idx++).toIntegerPreserveNaN(exec);
ok = isfinite(years);
t->setYear(toInt32(years - 1900));
t->setYear(toInt32(years));
}
// months
if (maxArgs >= 2 && idx < numArgs && ok) {
......@@ -567,10 +567,10 @@ EncodedJSValue JSC_HOST_CALL dateProtoFuncToISOString(ExecState* exec)
int ms = static_cast<int>(fmod(thisDateObj->internalNumber(), msPerSecond));
if (ms < 0)
ms += msPerSecond;
if (gregorianDateTime->year() > 8099 || gregorianDateTime->year() < -1900)
snprintf(buffer, sizeof(buffer) - 1, "%+07d-%02d-%02dT%02d:%02d:%02d.%03dZ", 1900 + gregorianDateTime->year(), gregorianDateTime->month() + 1, gregorianDateTime->monthDay(), gregorianDateTime->hour(), gregorianDateTime->minute(), gregorianDateTime->second(), ms);
if (gregorianDateTime->year() > 9999 || gregorianDateTime->year() < 0)
snprintf(buffer, sizeof(buffer) - 1, "%+07d-%02d-%02dT%02d:%02d:%02d.%03dZ", gregorianDateTime->year(), gregorianDateTime->month() + 1, gregorianDateTime->monthDay(), gregorianDateTime->hour(), gregorianDateTime->minute(), gregorianDateTime->second(), ms);
else
snprintf(buffer, sizeof(buffer) - 1, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", 1900 + gregorianDateTime->year(), gregorianDateTime->month() + 1, gregorianDateTime->monthDay(), gregorianDateTime->hour(), gregorianDateTime->minute(), gregorianDateTime->second(), ms);
snprintf(buffer, sizeof(buffer) - 1, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", gregorianDateTime->year(), gregorianDateTime->month() + 1, gregorianDateTime->monthDay(), gregorianDateTime->hour(), gregorianDateTime->minute(), gregorianDateTime->second(), ms);
buffer[sizeof(buffer) - 1] = 0;
return JSValue::encode(jsNontrivialString(exec, buffer));
}
......@@ -657,7 +657,7 @@ EncodedJSValue JSC_HOST_CALL dateProtoFuncGetFullYear(ExecState* exec)
const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTime(exec);
if (!gregorianDateTime)
return JSValue::encode(jsNaN());
return JSValue::encode(jsNumber(1900 + gregorianDateTime->year()));
return JSValue::encode(jsNumber(gregorianDateTime->year()));
}
EncodedJSValue JSC_HOST_CALL dateProtoFuncGetUTCFullYear(ExecState* exec)
......@@ -671,7 +671,7 @@ EncodedJSValue JSC_HOST_CALL dateProtoFuncGetUTCFullYear(ExecState* exec)
const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTimeUTC(exec);
if (!gregorianDateTime)
return JSValue::encode(jsNaN());
return JSValue::encode(jsNumber(1900 + gregorianDateTime->year()));
return JSValue::encode(jsNumber(gregorianDateTime->year()));
}
EncodedJSValue JSC_HOST_CALL dateProtoFuncToGMTString(ExecState* exec)
......@@ -1116,7 +1116,7 @@ EncodedJSValue JSC_HOST_CALL dateProtoFuncSetYear(ExecState* exec)
return JSValue::encode(result);
}
gregorianDateTime.setYear(toInt32((year > 99 || year < 0) ? year - 1900 : year));
gregorianDateTime.setYear(toInt32((year >= 0 && year <= 99) ? (year + 1900) : year));
JSValue result = jsNumber(gregorianDateTimeToMS(exec, gregorianDateTime, ms, false));
thisDateObj->setInternalValue(exec->globalData(), result);
return JSValue::encode(result);
......
......@@ -203,7 +203,7 @@ double getUTCOffset(ExecState* exec)
double gregorianDateTimeToMS(ExecState* exec, const GregorianDateTime& t, double milliSeconds, bool inputIsUTC)
{
double day = dateToDaysFrom1970(t.year() + 1900, t.month(), t.monthDay());
double day = dateToDaysFrom1970(t.year(), t.month(), t.monthDay());
double ms = timeToMS(t.hour(), t.minute(), t.second(), milliSeconds);
double result = (day * WTF::msPerDay) + ms;
......@@ -235,7 +235,7 @@ void msToGregorianDateTime(ExecState* exec, double ms, bool outputIsUTC, Gregori
tm.setYearDay(dayInYear(ms, year));
tm.setMonthDay(dayInMonthFromDayInYear(tm.yearDay(), isLeapYear(year)));
tm.setMonth(monthFromDayInYear(tm.yearDay(), isLeapYear(year)));
tm.setYear(year - 1900);
tm.setYear(year);
tm.setIsDST(dstOff != 0.0);
tm.setUtcOffset(static_cast<long>((dstOff + utcOff) / WTF::msPerSecond));
}
......
2012-07-24 Patrick Gansterer <paroga@webkit.org>
Store the full year in GregorianDateTime
https://bugs.webkit.org/show_bug.cgi?id=92067
Reviewed by Geoffrey Garen.
Use the full year instead of the offset from year 1900
for the year member variable of GregorianDateTime.
* wtf/GregorianDateTime.h:
(WTF::GregorianDateTime::operator tm):
2012-07-23 Patrick Gansterer <paroga@webkit.org>
Move GregorianDateTime from JSC to WTF namespace
......
......@@ -73,7 +73,7 @@ public:
tm ret;
memset(&ret, 0, sizeof(ret));
ret.tm_year = m_year;
ret.tm_year = m_year - 1900;
ret.tm_mon = m_month;
ret.tm_yday = m_yearDay;
ret.tm_mday = m_monthDay;
......
2012-07-24 Patrick Gansterer <paroga@webkit.org>
Store the full year in GregorianDateTime
https://bugs.webkit.org/show_bug.cgi?id=92067
Reviewed by Geoffrey Garen.
Use the full year instead of the offset from year 1900
for the year member variable of GregorianDateTime.
* bridge/qt/qt_runtime.cpp:
(JSC::Bindings::convertValueToQVariant):
(JSC::Bindings::convertQVariantToValue):
* bridge/qt/qt_runtime_qt4.cpp:
(JSC::Bindings::convertValueToQVariant):
(JSC::Bindings::convertQVariantToValue):
2012-07-24 Benjamin Poulain <bpoulain@apple.com>
Do not perform 8 to 16bits characters conversion when converting a WTFString to NSString/CFString
......@@ -504,10 +504,10 @@ QVariant convertValueToQVariant(ExecState* exec, JSValue value, QMetaType::Type
GregorianDateTime gdt;
msToGregorianDateTime(exec, date->internalNumber(), true, gdt);
if (hint == QMetaType::QDateTime) {
ret = QDateTime(QDate(gdt.year() + 1900, gdt.month() + 1, gdt.monthDay()), QTime(gdt.hour(), gdt.minute(), gdt.second()), Qt::UTC);
ret = QDateTime(QDate(gdt.year(), gdt.month() + 1, gdt.monthDay()), QTime(gdt.hour(), gdt.minute(), gdt.second()), Qt::UTC);
dist = 0;
} else if (hint == QMetaType::QDate) {
ret = QDate(gdt.year() + 1900, gdt.month() + 1, gdt.monthDay());
ret = QDate(gdt.year(), gdt.month() + 1, gdt.monthDay());
dist = 1;
} else {
ret = QTime(gdt.hour(), gdt.minute(), gdt.second());
......@@ -518,10 +518,10 @@ QVariant convertValueToQVariant(ExecState* exec, JSValue value, QMetaType::Type
GregorianDateTime gdt;
msToGregorianDateTime(exec, b, true, gdt);
if (hint == QMetaType::QDateTime) {
ret = QDateTime(QDate(gdt.year() + 1900, gdt.month() + 1, gdt.monthDay()), QTime(gdt.hour(), gdt.minute(), gdt.second()), Qt::UTC);
ret = QDateTime(QDate(gdt.year(), gdt.month() + 1, gdt.monthDay()), QTime(gdt.hour(), gdt.minute(), gdt.second()), Qt::UTC);
dist = 6;
} else if (hint == QMetaType::QDate) {
ret = QDate(gdt.year() + 1900, gdt.month() + 1, gdt.monthDay());
ret = QDate(gdt.year(), gdt.month() + 1, gdt.monthDay());
dist = 8;
} else {
ret = QTime(gdt.hour(), gdt.minute(), gdt.second());
......@@ -874,7 +874,7 @@ JSValue convertQVariantToValue(ExecState* exec, PassRefPtr<RootObject> root, con
// Dates specified this way are in local time (we convert DateTimes above)
GregorianDateTime dt;
dt.setYear(date.year() - 1900);
dt.setYear(date.year());
dt.setMonth(date.month() - 1);
dt.setMonthDay(date.day());
dt.setHour(time.hour());
......
......@@ -504,10 +504,10 @@ QVariant convertValueToQVariant(ExecState* exec, JSValue value, QMetaType::Type
GregorianDateTime gdt;
msToGregorianDateTime(exec, date->internalNumber(), true, gdt);
if (hint == QMetaType::QDateTime) {
ret = QDateTime(QDate(gdt.year() + 1900, gdt.month() + 1, gdt.monthDay()), QTime(gdt.hour(), gdt.minute(), gdt.second()), Qt::UTC);
ret = QDateTime(QDate(gdt.year(), gdt.month() + 1, gdt.monthDay()), QTime(gdt.hour(), gdt.minute(), gdt.second()), Qt::UTC);
dist = 0;
} else if (hint == QMetaType::QDate) {
ret = QDate(gdt.year() + 1900, gdt.month() + 1, gdt.monthDay());
ret = QDate(gdt.year(), gdt.month() + 1, gdt.monthDay());
dist = 1;
} else {
ret = QTime(gdt.hour(), gdt.minute(), gdt.second());
......@@ -518,10 +518,10 @@ QVariant convertValueToQVariant(ExecState* exec, JSValue value, QMetaType::Type
GregorianDateTime gdt;
msToGregorianDateTime(exec, b, true, gdt);
if (hint == QMetaType::QDateTime) {
ret = QDateTime(QDate(gdt.year() + 1900, gdt.month() + 1, gdt.monthDay()), QTime(gdt.hour(), gdt.minute(), gdt.second()), Qt::UTC);
ret = QDateTime(QDate(gdt.year(), gdt.month() + 1, gdt.monthDay()), QTime(gdt.hour(), gdt.minute(), gdt.second()), Qt::UTC);
dist = 6;
} else if (hint == QMetaType::QDate) {
ret = QDate(gdt.year() + 1900, gdt.month() + 1, gdt.monthDay());
ret = QDate(gdt.year(), gdt.month() + 1, gdt.monthDay());
dist = 8;
} else {
ret = QTime(gdt.hour(), gdt.minute(), gdt.second());
......@@ -874,7 +874,7 @@ JSValue convertQVariantToValue(ExecState* exec, PassRefPtr<RootObject> root, con
// Dates specified this way are in local time (we convert DateTimes above)
GregorianDateTime dt;
dt.setYear(date.year() - 1900);
dt.setYear(date.year());
dt.setMonth(date.month() - 1);
dt.setMonthDay(date.day());
dt.setHour(time.hour());
......
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