From: Iskren Chernev Date: Tue, 8 Jan 2013 05:30:03 +0000 (-0800) Subject: toString now returns a fixed format that looks like unix data X-Git-Tag: 2.0.0~25^2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F566%2Fhead;p=thirdparty%2Fmoment.git 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. --- 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(); } };