From: Klaus Jrgensen Date: Wed, 17 Jul 2013 20:02:39 +0000 (+0200) Subject: allow initializing with unix timestamp as integer X-Git-Tag: 2.2.0~44^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F930%2Fhead;p=thirdparty%2Fmoment.git allow initializing with unix timestamp as integer --- diff --git a/moment.js b/moment.js index c1673c127..02bb1dded 100644 --- a/moment.js +++ b/moment.js @@ -812,7 +812,7 @@ function makeDateFromStringAndFormat(config) { // This array is used to make a Date, either with `new Date` or `Date.UTC` var tokens = config._f.match(formattingTokens), - string = config._i, + string = '' + config._i, i, parsedInput; config._a = []; diff --git a/test/moment/format.js b/test/moment/format.js index 6408bb60e..1265a5944 100644 --- a/test/moment/format.js +++ b/test/moment/format.js @@ -88,7 +88,7 @@ exports.format = { }, "unix timestamp" : function (test) { - test.expect(4); + test.expect(5); var m = moment('1234567890.123', 'X'); test.equals(m.format('X'), '1234567890', 'unix timestamp without milliseconds'); @@ -96,6 +96,9 @@ exports.format = { test.equals(m.format('X.SS'), '1234567890.12', 'unix timestamp with centiseconds'); test.equals(m.format('X.SSS'), '1234567890.123', 'unix timestamp with milliseconds'); + m = moment(1234567890.123, 'X'); + test.equals(m.format('X'), '1234567890', 'unix timestamp as integer'); + test.done(); },