From d3842dbd6f99f5241ee0d803501950806b55d293 Mon Sep 17 00:00:00 2001 From: Iskren Chernev Date: Mon, 7 Jan 2013 21:30:03 -0800 Subject: [PATCH] toString now returns a fixed format that looks like unix data This is actually fixing #475 -- toString on utc moments was returning localized format. This commit fixes the issue and also makes sure that toString will work uniformly on all browsers from now on. --- moment.js | 2 +- test/moment/create.js | 7 ------- test/moment/format.js | 8 ++++++++ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/moment.js b/moment.js index b45633ba8..1d9cbcf84 100644 --- a/moment.js +++ b/moment.js @@ -1028,7 +1028,7 @@ }, toString : function () { - return this._d.toString(); + return this.format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ"); }, toDate : function () { diff --git a/test/moment/create.js b/test/moment/create.js index 41defc753..2be29b53d 100644 --- a/test/moment/create.js +++ b/test/moment/create.js @@ -69,13 +69,6 @@ exports.create = { test.done(); }, - "string from Date.toString" : function(test) { - test.expect(1); - var str = (new Date()).toString(); - test.equal(moment(str).toString(), str, "Parsing a string from Date.prototype.toString should match moment.fn.toString"); - test.done(); - }, - "string without format - json" : function(test) { test.expect(5); test.equal(moment("Date(1325132654000)").valueOf(), 1325132654000, "Date(1325132654000)"); diff --git a/test/moment/format.js b/test/moment/format.js index 0d3365544..769f26b01 100644 --- a/test/moment/format.js +++ b/test/moment/format.js @@ -166,6 +166,14 @@ exports.format = { test.equal(iso, the, i + ": should be " + iso + ", but " + the); } + test.done(); + }, + + "toString is just human readable format" : function(test) { + test.expect(1); + + 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(); } }; -- 2.47.2