From ea364d127f825310406fde4cd5d1e1aab083f685 Mon Sep 17 00:00:00 2001 From: Klaus Jrgensen Date: Wed, 17 Jul 2013 22:02:39 +0200 Subject: [PATCH] allow initializing with unix timestamp as integer --- moment.js | 2 +- test/moment/format.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) 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(); }, -- 2.47.2