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

When all parsing fails, uses date parsing. If that fails, gives the c… #526

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions js/bootstrap-datetimepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,8 @@
}
return UTCDate(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), 0);
}

var originalDate = date;
var parts = date && date.toString().match(this.nonpunctuation) || [],
date = new Date(0, 0, 0, 0, 0, 0, 0),
parsed = {},
Expand Down Expand Up @@ -1631,6 +1633,17 @@
setters_map[s](date, parsed[s])
}
}
//No parsing worked, so attempt to just use Date's parsing
else {
var dateInstance = new Date(originalDate);
if (dateInstance.toString() !== 'Invalid Date') {
return this.parseDate(dateInstance);
//Not even date parsing worked. Send back the current date time
} else {
return this.parseDate(new Date());
}
}

return date;
},
formatDate: function (date, format, language, type) {
Expand Down
8 changes: 8 additions & 0 deletions tests/suites/formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,11 @@ test('Untrimmed datetime value', patch_date(function(Date){
.datetimepicker('setValue');
equal(this.input.val(), '2012-03-05 00:00');
}));

test('When parsing does not work uses date parsing', function(){
this.input
.val('8/19/1986')
.datetimepicker({format: 'mm/dd/yy HH:ii P'})
.datetimepicker('setValue');
equal(this.input.val(), '08/19/86 12:00 AM');
});