Skip to content

Commit

Permalink
Merge pull request #4694 from scampi/undefined-date
Browse files Browse the repository at this point in the history
missing date patch
  • Loading branch information
jbudz committed Aug 19, 2015
2 parents 8a2e4da + 1857daf commit c416a9f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/ui/public/stringify/__tests__/_date.js
@@ -0,0 +1,20 @@
describe('Date Format', function () {
var fieldFormats;
var expect = require('expect.js');
var ngMock = require('ngMock');

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
fieldFormats = Private(require('ui/registry/field_formats'));
}));

it('decoding an undefined or null date should return an empty string', function () {
var DateFormat = fieldFormats.getType('date');
var date = new DateFormat({
pattern: 'dd-MM-yyyy'
});
expect(date.convert(null)).to.be('');
expect(date.convert(undefined)).to.be('');
});

});
1 change: 1 addition & 0 deletions src/ui/public/stringify/__tests__/index.js
Expand Up @@ -4,4 +4,5 @@ describe('Stringify Component', function () {
require('./_source');
require('./_string');
require('./_url');
require('./_date');
});
3 changes: 3 additions & 0 deletions src/ui/public/stringify/types/Date.js
Expand Up @@ -45,6 +45,9 @@ define(function (require) {
if (this._memoizedPattern !== pattern) {
this._memoizedPattern = pattern;
this._memoizedConverter = _.memoize(function converter(val) {
if (val === null || val === undefined) {
return '';
}
return moment(val).format(pattern);
});
}
Expand Down

0 comments on commit c416a9f

Please sign in to comment.