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

letting native date construct date #923

Merged
Changes from 1 commit
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
11 changes: 10 additions & 1 deletion js/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,16 @@
if(date){
if(this.moment){ //if we have moment, use that to parse the dates
momentParse = function(type, d){
d = (type==='b') ? moment(d, self.momentFormat) : moment(d);
if(type==='b') {
d = moment(d, self.momentFormat);
}
else {
// moment shows deprecated warning if sent poorly formated string
// building via "new Date" first
// still possible unpredictable results if the string is kindof well formated
d = moment( new Date(d) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure just sending the string through new Date here is a good idea. Newing up Date objects can throw exceptions if the string if not formatted correctly, which is handled down lower on line 371. This should probably either be safer, or this entire chunk of code re-written to consolidate some of the error handling code pieces.

}

return (d.isValid()===true) ? d.toDate() : new Date(NaN);
};
use = (typeof(date)==='string') ? ['b', 'a'] : ['a', 'b'];
Expand Down