From 6a5af4bab49071ef43ce680f97e01af58ae6a968 Mon Sep 17 00:00:00 2001 From: "mrbkap%gmail.com" Date: Mon, 17 Oct 2005 21:57:45 +0000 Subject: [PATCH] bug 307895: Date.toLocalFormat("%x") with format yyyy/MM/dd produces yyyy/MM/yyyy. Patch from gekacheka@yahoo.com. r=brendan --- js/src/jsdate.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/js/src/jsdate.c b/js/src/jsdate.c index a76502c38e07..a1b99a97d0a3 100644 --- a/js/src/jsdate.c +++ b/js/src/jsdate.c @@ -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)); }