Skip to content

Commit

Permalink
fix(calendar): do not pass numeric-only text to date constructor
Browse files Browse the repository at this point in the history
The current code expects parsing on partial input, e.g. 1, to be failed on new Date("1").
However, there are incosintency between browsers on how new Date consturctor or Date.parse works.
input	Chrome	Firefox
new Date("1")	success	invalid
new Date("10")	success	invalid
new Date("100")	success	invalid
new Date("1000")	success	success
On Chrome, new Date("1") or such can create instance of Date.
So, getDate is a number, then hour is not chosen correctly.

This PR adds a check input is number-only `^[0-9]+$ or not.
If input is number-only, it should go to time-only or date-only logic.
  • Loading branch information
exoego authored Jul 12, 2020
1 parent ecf370b commit 2239f64
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/definitions/modules/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,8 @@ $.fn.calendar.settings = {
// Reverse date and month in some cases
text = settings.monthFirst || !text.match(/^[0-9]{2}[\/\-\.]/) ? text : text.replace(/[\/\-\.]/g,'/').replace(/([0-9]+)\/([0-9]+)/,'$2/$1');
var textDate = new Date(text);
if(!isNaN(textDate.getDate())) {
var numberOnly = text.match(/^[0-9]+$/) !== null;
if(!numberOnly && !isNaN(textDate.getDate())) {
return textDate;
}
text = text.toLowerCase();
Expand Down

0 comments on commit 2239f64

Please sign in to comment.