Skip to content

Commit

Permalink
Fix Issue exceljs#488 where dt is an invalid date format. Check the v…
Browse files Browse the repository at this point in the history
…alue and return blank string. Add unit test.
  • Loading branch information
ilijaz committed Jun 11, 2018
1 parent 832c441 commit b5336ca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/xlsx/xform/simple/date-xform.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ var DateXform = module.exports = function(options) {
this.tag = options.tag;
this.attr = options.attr;
this.attrs = options.attrs;
this._format = options.format || function(dt) { return dt.toISOString(); };
this._format = options.format || function(dt) {
if (isNaN(dt.getTime())) return '';
return dt.toISOString();
};
this._parse = options.parse || function(str) { return new Date(str); };
};

Expand Down
9 changes: 9 additions & 0 deletions spec/unit/xlsx/xform/simple/date-xform.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,16 @@ var expectations = [
preparedModel: undefined,
xml: '',
tests: ['render', 'renderIn']
},
{
title: 'invalid date',
create: function() { return new DateXform({tag: 'date', attr: undefined}); },
preparedModel: new Date(undefined),
xml: '<date />',
tests: ['render']
}


];

describe('DateXform', function() {
Expand Down

0 comments on commit b5336ca

Please sign in to comment.