зеркало из https://github.com/mozilla/pjs.git
Back out changes which are breaking builds (at request of mccabe)
This commit is contained in:
Родитель
211dce8234
Коммит
69505fcd61
111
js/src/jsdate.c
111
js/src/jsdate.c
|
@ -1391,35 +1391,11 @@ date_toGMTString(JSContext *cx, JSObject *obj, uintN argc,
|
|||
return JS_TRUE;
|
||||
}
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
/* for Date.toLocaleString; interface to PRMJTime date struct. */
|
||||
static void
|
||||
new_explode(jsdouble time, PRMJTime *split, JSBool findEquivalent)
|
||||
new_explode(jsdouble time, PRMJTime *split)
|
||||
{
|
||||
jsint year = YearFromTime(time);
|
||||
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 = year - cycles * CYCLE_YEARS;
|
||||
} else {
|
||||
/* Clamp it to the nearest representable year. */
|
||||
adjustedYear = (year > 0) ? 32767 : - 32768;
|
||||
}
|
||||
} else {
|
||||
adjustedYear = (int16)year;
|
||||
}
|
||||
|
||||
split->tm_usec = (int32) msFromTime(time) * 1000;
|
||||
split->tm_sec = (int8) SecFromTime(time);
|
||||
|
@ -1428,7 +1404,7 @@ new_explode(jsdouble time, PRMJTime *split, JSBool findEquivalent)
|
|||
split->tm_mday = (int8) DateFromTime(time);
|
||||
split->tm_mon = (int8) MonthFromTime(time);
|
||||
split->tm_wday = (int8) WeekDay(time);
|
||||
split->tm_year = (int16) adjustedYear;
|
||||
split->tm_year = (int16) year;
|
||||
split->tm_yday = (int16) DayWithinYear(time, year);
|
||||
|
||||
/* not sure how this affects things, but it doesn't seem
|
||||
|
@ -1436,6 +1412,43 @@ new_explode(jsdouble time, PRMJTime *split, JSBool findEquivalent)
|
|||
split->tm_isdst = (DaylightSavingTA(time) != 0);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
date_toLocaleString(JSContext *cx, JSObject *obj, uintN argc,
|
||||
jsval *argv, jsval *rval)
|
||||
{
|
||||
char buf[100];
|
||||
JSString *str;
|
||||
PRMJTime split;
|
||||
jsdouble *date = date_getProlog(cx, obj, argv);
|
||||
if (!date)
|
||||
return JS_FALSE;
|
||||
|
||||
if (!JSDOUBLE_IS_FINITE(*date)) {
|
||||
PR_snprintf(buf, sizeof buf, js_NaN_date_str);
|
||||
} else {
|
||||
jsdouble local = LocalTime(*date);
|
||||
new_explode(local, &split);
|
||||
|
||||
/* let PRMJTime format it. Use '%#c' for windows, because '%c' is
|
||||
* backward-compatible and non-y2k with msvc; '%#c' requests that a
|
||||
* full year be used in the result string.
|
||||
*/
|
||||
PRMJ_FormatTime(buf, sizeof buf,
|
||||
#ifdef _WIN32
|
||||
"%#c",
|
||||
#else
|
||||
"%c",
|
||||
#endif
|
||||
&split);
|
||||
}
|
||||
|
||||
str = JS_NewStringCopyZ(cx, buf);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
*rval = STRING_TO_JSVAL(str);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
/* helper function */
|
||||
static JSBool
|
||||
date_format(JSContext *cx, jsdouble date, jsval *rval)
|
||||
|
@ -1469,7 +1482,7 @@ date_format(JSContext *cx, jsdouble date, jsval *rval)
|
|||
|
||||
/* get a timezone string from the OS to include as a
|
||||
comment. */
|
||||
new_explode(date, &split, JS_TRUE);
|
||||
new_explode(date, &split);
|
||||
PRMJ_FormatTime(tzbuf, sizeof tzbuf, "(%Z) ", &split);
|
||||
|
||||
/* Avoid dependence on PRMJ_FormatTimeUSEnglish, because it
|
||||
|
@ -1499,48 +1512,6 @@ date_format(JSContext *cx, jsdouble date, jsval *rval)
|
|||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
date_toLocaleString(JSContext *cx, JSObject *obj, uintN argc,
|
||||
jsval *argv, jsval *rval)
|
||||
{
|
||||
char buf[100];
|
||||
JSString *str;
|
||||
PRMJTime split;
|
||||
jsdouble *date = date_getProlog(cx, obj, argv);
|
||||
if (!date)
|
||||
return JS_FALSE;
|
||||
|
||||
if (!JSDOUBLE_IS_FINITE(*date)) {
|
||||
PR_snprintf(buf, sizeof buf, js_NaN_date_str);
|
||||
} else {
|
||||
intN result_len;
|
||||
jsdouble local = LocalTime(*date);
|
||||
new_explode(local, &split, JS_FALSE);
|
||||
|
||||
/* let PRMJTime format it. Use '%#c' for windows, because '%c' is
|
||||
* backward-compatible and non-y2k with msvc; '%#c' requests that a
|
||||
* full year be used in the result string.
|
||||
*/
|
||||
result_len = PRMJ_FormatTime(buf, sizeof buf,
|
||||
#ifdef _WIN32
|
||||
"%#c",
|
||||
#else
|
||||
"%c",
|
||||
#endif
|
||||
&split);
|
||||
|
||||
/* If it failed, default to toString. */
|
||||
if (result_len == 0)
|
||||
return date_format(cx, *date, rval);
|
||||
}
|
||||
|
||||
str = JS_NewStringCopyZ(cx, buf);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
*rval = STRING_TO_JSVAL(str);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
#if JS_HAS_TOSOURCE
|
||||
#include "prdtoa.h"
|
||||
|
||||
|
|
|
@ -158,6 +158,10 @@ PRMJ_LocalGMTDifference()
|
|||
#define G2037GMTMICROHI 0x00e45fab /* micro secs to 2037 high */
|
||||
#define G2037GMTMICROLOW 0x7a238000 /* micro secs to 2037 low */
|
||||
|
||||
/* Convert from extended time to base time (time since Jan 1 1970) it
|
||||
* truncates dates if time is before 1970 and after 2037.
|
||||
*/
|
||||
|
||||
/* Convert from base time to extended time */
|
||||
PR_IMPLEMENT(PRInt64)
|
||||
PRMJ_ToExtendedTime(PRInt32 time)
|
||||
|
@ -283,10 +287,10 @@ PRMJ_DSTOffset(PRInt64 time)
|
|||
PRInt32 diff;
|
||||
PRInt64 maxtimet;
|
||||
struct tm tm;
|
||||
PRTime prtm;
|
||||
#if defined( XP_PC ) || defined( FREEBSD ) || defined ( HPUX9 )
|
||||
struct tm *ptm;
|
||||
#endif
|
||||
PRMJTime prtm;
|
||||
|
||||
|
||||
LL_UI2L(us2s, PRMJ_USEC_PER_SEC);
|
||||
|
@ -368,19 +372,12 @@ PRMJ_FormatTime(char *buf, int buflen, char *fmt, PRMJTime *prtm)
|
|||
* Still not sure if MKLINUX is necessary; this is borrowed from the NSPR20
|
||||
* prtime.c. I'm leaving it out - My Linux does the right thing without it
|
||||
* (and the wrong thing with it) even though it has the tm_gmtoff, tm_zone
|
||||
* fields. Linux seems to be happy so long as the tm struct is zeroed out.
|
||||
* The #ifdef in nspr is:
|
||||
* #if defined(SUNOS4) || defined(MKLINUX) || defined (__GLIBC >= 2)
|
||||
* fields.
|
||||
*/
|
||||
|
||||
#if defined(SUNOS4)
|
||||
if (mktime(&a) == -1) {
|
||||
/* Seems to fail whenever the requested date is outside of the 32-bit
|
||||
* UNIX epoch. We could proceed at this point (setting a.tm_zone to
|
||||
* "") but then strftime returns a string with a 2-digit field of
|
||||
* garbage for the year. So we return 0 and hope jsdate.c
|
||||
* will fall back on toString.
|
||||
*/
|
||||
PR_snprintf(buf, buflen, "can't get timezone");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
Загрузка…
Ссылка в новой задаче