bug 307895: Date.toLocalFormat("%x") with format yyyy/MM/dd produces yyyy/MM/yyyy. Patch from gekacheka@yahoo.com. r=brendan

This commit is contained in:
mrbkap%gmail.com 2005-10-17 21:57:45 +00:00
parent d08f38656a
commit 6a5af4bab4

View File

@ -1768,8 +1768,14 @@ date_toLocaleHelper(JSContext *cx, JSObject *obj, uintN argc,
return date_format(cx, *date, FORMATSPEC_FULL, rval);
/* Hacked check against undesired 2-digit year 00/00/00 form. */
if (buf[result_len - 3] == '/' &&
isdigit(buf[result_len - 2]) && isdigit(buf[result_len - 1])) {
if (strcmp(format, "%x") == 0 && result_len >= 6 &&
/* Format %x means use OS settings, which may have 2-digit yr, so
hack end of 3/11/22 or 11.03.22 or 11Mar22 to use 4-digit yr...*/
!isdigit(buf[result_len - 3]) &&
isdigit(buf[result_len - 2]) && isdigit(buf[result_len - 1]) &&
/* ...but not if starts with 4-digit year, like 2022/3/11. */
!(isdigit(buf[0]) && isdigit(buf[1]) &&
isdigit(buf[2]) && isdigit(buf[3]))) {
JS_snprintf(buf + (result_len - 2), (sizeof buf) - (result_len - 2),
"%d", js_DateGetYear(cx, obj));
}