Merge pull request #1741 from strongloop/fix/datestring-ctor-3x

Fix DateString ctor to accept DateString instances
This commit is contained in:
Miroslav Bajtoš 2019-05-13 16:32:37 +02:00 committed by GitHub
commit 548f3018a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);