Skip to content
Snippets Groups Projects
Commit 8822231a authored by reed@reedloden.com's avatar reed@reedloden.com
Browse files

Bug 398485 - "Date toLocaleString() clamps the year to -32767 .. 32767"...

Bug 398485 - "Date toLocaleString() clamps the year to -32767 .. 32767" [p=mats.palmgren@bredband.net (Mats Palmgren) r=crowder a1.9=schrep]
parent 5ea89f0b
No related branches found
No related tags found
No related merge requests found
......@@ -1612,34 +1612,11 @@ date_toGMTString(JSContext *cx, uintN argc, jsval *vp)
}
/* for Date.toLocaleString; interface to PRMJTime date struct.
* If findEquivalent is true, then try to map the year to an equivalent year
* that's in range.
*/
static void
new_explode(jsdouble timeval, PRMJTime *split, JSBool findEquivalent)
new_explode(jsdouble timeval, PRMJTime *split)
{
jsint year = YearFromTime(timeval);
int16 adjustedYear;
/* If the year doesn't fit in a PRMJTime, find something to do about it. */
if (year > 32767 || year < -32768) {
if (findEquivalent) {
/* We're really just trying to get a timezone string; map the year
* to some equivalent year in the range 0 to 2800. Borrowed from
* A. D. Olsen.
*/
jsint cycles;
#define CYCLE_YEARS 2800L
cycles = (year >= 0) ? year / CYCLE_YEARS
: -1 - (-1 - year) / CYCLE_YEARS;
adjustedYear = (int16)(year - cycles * CYCLE_YEARS);
} else {
/* Clamp it to the nearest representable year. */
adjustedYear = (int16)((year > 0) ? 32767 : - 32768);
}
} else {
adjustedYear = (int16)year;
}
split->tm_usec = (int32) msFromTime(timeval) * 1000;
split->tm_sec = (int8) SecFromTime(timeval);
......@@ -1648,7 +1625,7 @@ new_explode(jsdouble timeval, PRMJTime *split, JSBool findEquivalent)
split->tm_mday = (int8) DateFromTime(timeval);
split->tm_mon = (int8) MonthFromTime(timeval);
split->tm_wday = (int8) WeekDay(timeval);
split->tm_year = (int16) adjustedYear;
split->tm_year = year;
split->tm_yday = (int16) DayWithinYear(timeval, year);
/* not sure how this affects things, but it doesn't seem
......@@ -1694,7 +1671,7 @@ date_format(JSContext *cx, jsdouble date, formatspec format, jsval *rval)
/* get a timezone string from the OS to include as a
comment. */
new_explode(date, &split, JS_TRUE);
new_explode(date, &split);
if (PRMJ_FormatTime(tzbuf, sizeof tzbuf, "(%Z)", &split) != 0) {
/* Decide whether to use the resulting timezone string.
......@@ -1792,7 +1769,7 @@ date_toLocaleHelper(JSContext *cx, const char *format, jsval *vp)
} else {
intN result_len;
jsdouble local = LocalTime(utctime);
new_explode(local, &split, JS_FALSE);
new_explode(local, &split);
/* let PRMJTime format it. */
result_len = PRMJ_FormatTime(buf, sizeof buf, format, &split);
......
......@@ -64,7 +64,7 @@ struct PRMJTime {
JSInt8 tm_mday; /* day of month (1-31) */
JSInt8 tm_mon; /* month of year (0-11) */
JSInt8 tm_wday; /* 0=sunday, 1=monday, ... */
JSInt16 tm_year; /* absolute year, AD */
JSInt32 tm_year; /* absolute year, AD */
JSInt16 tm_yday; /* day of year (0 to 365) */
JSInt8 tm_isdst; /* non-zero if DST in effect */
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment