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);