Skip to content

Commit

Permalink
additional testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Afsin Ustundag committed Mar 8, 2015
1 parent 446c0e8 commit d6ae8eb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/datetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ var modelToDateTime = exports.modelToDateTime = (function () {
return moment(t, 'YYYYMM').format('YYYY-MM');
},
day: function (t) {
return moment(t, 'YYYYMMDD').format('YYYY-MM-DD');
} // Other precisions to be implemented
return moment(t, 'YYYYMMDD').format('YYYY-MM-DD');
}
};

return function (dt) {
Expand Down
32 changes: 31 additions & 1 deletion test/test-datetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var bbu = require('../index');
var expect = chai.expect;
var datetime = bbu.datetime;

describe('datetime: iso->model->iso compare', function () {
describe('datetime: dateToModel->modelToDate->dateToModel', function () {
['2012', '2012-05', '2012-05-23'].forEach(function (input) {
it(input, function () {
var model = datetime.dateToModel(input);
Expand All @@ -17,3 +17,33 @@ describe('datetime: iso->model->iso compare', function () {
});
});
});

describe('datetime: dateTimeToModel->modelToDateTime->dateTimeToModel', function () {
['2012-05-23', '2015-03-07T16:44:28.730Z'].forEach(function (input) {
it(input, function () {
var model = datetime.dateTimeToModel(input);
expect(model).to.exist();
var reInput = datetime.modelToDateTime(model);
expect(reInput).to.equal(input);
});
});
});

describe('dateTime.modelToDate', function () {
it('higher precision', function () {
var input = {
date: '2015-03-07T16:44:28.000Z',
precision: 'second'
};
var actual = datetime.modelToDate(input);
expect(actual).to.equal('2015-03-07');
});
});

describe('dateTime.dateToModel', function () {
it('error', function () {
var input = '2015-15-07T16:44:28.000Z';
var actual = datetime.dateToModel(input);
expect(actual).to.equal(null);
});
});

0 comments on commit d6ae8eb

Please sign in to comment.