From f4cbcc5f97cbf775be026e04e9eda9badd198417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 13 May 2019 15:21:00 +0200 Subject: [PATCH] Fix DateString ctor to accept DateString instances MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miroslav Bajtoš --- lib/date-string.js | 4 ++++ test/date-string.test.js | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/lib/date-string.js b/lib/date-string.js index 09a0bee1..bc84c7b9 100644 --- a/lib/date-string.js +++ b/lib/date-string.js @@ -53,6 +53,10 @@ function DateString(value) { return new DateString(value); } + if (value instanceof DateString) { + value = value.when; + } + if (typeof(value) !== 'string') { throw new Error('Input must be a string'); } diff --git a/test/date-string.test.js b/test/date-string.test.js index 1dbdb1da..f7d4172b 100644 --- a/test/date-string.test.js +++ b/test/date-string.test.js @@ -44,6 +44,13 @@ describe('DateString', function() { // The internal date representation should also be updated! date._date.toString().should.eql(d.toString()); }); + + it('should accept DateString instance', function() { + const input = new DateString('2015-01-01'); + const inst = new DateString(input); + inst.toString().should.equal('2015-01-01'); + }); + it('should return custom inspect output', function() { const date = new DateString('2015-01-01'); const result = inspect(date);