From 9701289bffdb45d17198db420daf2d306c9afd1f Mon Sep 17 00:00:00 2001 From: Iskren Chernev Date: Sat, 27 Apr 2013 00:02:41 -0700 Subject: [PATCH] toJSON should not call lang.postformat --- moment.js | 2 +- test/moment/format.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/moment.js b/moment.js index 0ebc5f5e9..5c2c87c24 100644 --- a/moment.js +++ b/moment.js @@ -1137,7 +1137,7 @@ }, toJSON : function () { - return moment(this).utc().format('YYYY-MM-DD[T]HH:mm:ss.SSS[Z]'); + return formatMoment(moment(this).utc(), 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]'); }, toArray : function () { diff --git a/test/moment/format.js b/test/moment/format.js index 4ce81df46..b91c61378 100644 --- a/test/moment/format.js +++ b/test/moment/format.js @@ -285,5 +285,13 @@ exports.format = { var b = moment(new Date(2009, 1, 5, 15, 25, 50, 125)); test.equal(b.toString(), b.format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ')); test.done(); + }, + + "toJSON skips postformat" : function(test) { + test.expect(1); + + moment.lang('postformat', {postformat: function(s) { s.replace(/./g, 'X') }}); + test.equal(moment.utc([2000, 0, 1]).toJSON(), "2000-01-01T00:00:00.000Z", "toJSON doesn't postformat"); + test.done(); } }; -- 2.47.2