[njs] Date.prototype.toUTCString() format was aligned to ES9.
Valentin Bartenev
vbart at nginx.com
Sat Sep 28 11:53:53 UTC 2019
details: https://hg.nginx.org/njs/rev/5c22e2f006fe
branches:
changeset: 1166:5c22e2f006fe
user: Valentin Bartenev <vbart at nginx.com>
date: Fri Sep 27 22:21:55 2019 +0300
description:
Date.prototype.toUTCString() format was aligned to ES9.
This closes #224 issue on GitHub.
diffstat:
src/njs_date.c | 12 +++++++-----
src/test/njs_unit_test.c | 4 ++--
2 files changed, 9 insertions(+), 7 deletions(-)
diffs (57 lines):
diff -r f516c8332495 -r 5c22e2f006fe src/njs_date.c
--- a/src/njs_date.c Thu Sep 19 10:19:02 2019 +0300
+++ b/src/njs_date.c Fri Sep 27 22:21:55 2019 +0300
@@ -14,7 +14,9 @@
* FreeBSD and MacOSX timegm() cannot handle years before 1900.
*/
-#define NJS_ISO_DATE_TIME_LEN sizeof("+001970-09-28T12:00:00.000Z")
+#define NJS_ISO_DATE_TIME_LEN sizeof("+001970-09-28T12:00:00.000Z")
+
+#define NJS_HTTP_DATE_TIME_LEN sizeof("Mon, 28 Sep 1970 12:00:00 GMT")
#define NJS_DATE_TIME_LEN \
sizeof("Mon Sep 28 1970 12:00:00 GMT+0600 (XXXXX)")
@@ -1009,7 +1011,7 @@ njs_date_prototype_to_utc_string(njs_vm_
{
double time;
time_t clock;
- u_char buf[NJS_DATE_TIME_LEN], *p;
+ u_char buf[NJS_HTTP_DATE_TIME_LEN], *p;
struct tm tm;
static const char *week[] = { "Sun", "Mon", "Tue", "Wed",
@@ -1024,9 +1026,9 @@ njs_date_prototype_to_utc_string(njs_vm_
clock = time / 1000;
gmtime_r(&clock, &tm);
- p = njs_sprintf(buf, buf + NJS_DATE_TIME_LEN,
- "%s %s %02d %4d %02d:%02d:%02d GMT",
- week[tm.tm_wday], month[tm.tm_mon], tm.tm_mday,
+ p = njs_sprintf(buf, buf + NJS_HTTP_DATE_TIME_LEN,
+ "%s, %02d %s %4d %02d:%02d:%02d GMT",
+ week[tm.tm_wday], tm.tm_mday, month[tm.tm_mon],
tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec);
return njs_string_new(vm, &vm->retval, buf, p - buf, p - buf);
diff -r f516c8332495 -r 5c22e2f006fe src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Thu Sep 19 10:19:02 2019 +0300
+++ b/src/test/njs_unit_test.c Fri Sep 27 22:21:55 2019 +0300
@@ -11323,7 +11323,7 @@ static njs_unit_test_t njs_test[] =
njs_str("18:45:00 GMT+0000") },
{ njs_str("var d = new Date(2011, 5, 24, 18, 45); d.toUTCString()"),
- njs_str("Fri Jun 24 2011 18:45:00 GMT") },
+ njs_str("Fri, 24 Jun 2011 18:45:00 GMT") },
{ njs_str("var d = new Date(2011, 5, 24, 18, 45, 12, 625);"
"d.toISOString()"),
@@ -14074,7 +14074,7 @@ static njs_unit_test_t njs_tz_test[] =
njs_str("18:45:00 GMT+1245") },
{ njs_str("var d = new Date(2011, 5, 24, 18, 45); d.toUTCString()"),
- njs_str("Fri Jun 24 2011 06:00:00 GMT") },
+ njs_str("Fri, 24 Jun 2011 06:00:00 GMT") },
{ njs_str("var d = new Date(2011, 5, 24, 18, 45, 12, 625);"
"d.toISOString()"),
More information about the nginx-devel
mailing list