Fix DateString ctor to accept DateString instances

Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
This commit is contained in:
Miroslav Bajtoš 2019-05-13 15:21:00 +02:00
parent 91ab3e9162
commit 5369cf3d54
No known key found for this signature in database
GPG Key ID: 6F2304BA9361C7E3
2 changed files with 11 additions and 0 deletions

View File

@ -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');
}

View File

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