Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
fix(dateparser): add type and validity check
Browse files Browse the repository at this point in the history
- Add type and validity check to ensure proper date object is created
- Make code style uniform in scripts

chore(dateparser): revert code style changes
  • Loading branch information
wesleycho committed Jun 8, 2015
1 parent 8297244 commit 09919d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/dateparser/dateparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ angular.module('ui.bootstrap.dateparser', [])

if ( results && results.length ) {
var fields, dt;
if (baseDate) {
if (angular.isDate(baseDate) && !isNaN(baseDate.getTime())) {
fields = {
year: baseDate.getFullYear(),
month: baseDate.getMonth(),
Expand Down
8 changes: 8 additions & 0 deletions src/dateparser/test/dateparser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ describe('date parser', function () {
expect(dateParser.parse('31-04-2013', 'dd-MM-yyyy')).toBeUndefined();
expect(dateParser.parse('November 31, 2013', 'MMMM d, yyyy')).toBeUndefined();
});

it('should work when base date is a string', function() {
expect(dateParser.parse('01-02-2034', 'dd-MM-yyyy', '05-06-2078')).toEqual(new Date(2034, 1, 1));
});

it('should work when base date is an invalid date', function() {
expect(dateParser.parse('30-12-2015', 'dd-MM-yyyy', new Date('foo'))).toEqual(new Date(2015, 11, 30));
});
});

it('should not parse non-string inputs', function() {
Expand Down

0 comments on commit 09919d0

Please sign in to comment.