Skip to content

Commit 2239f64

Browse files
authored
fix(calendar): do not pass numeric-only text to date constructor
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.
1 parent ecf370b commit 2239f64

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/definitions/modules/calendar.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,8 @@ $.fn.calendar.settings = {
13571357
// Reverse date and month in some cases
13581358
text = settings.monthFirst || !text.match(/^[0-9]{2}[\/\-\.]/) ? text : text.replace(/[\/\-\.]/g,'/').replace(/([0-9]+)\/([0-9]+)/,'$2/$1');
13591359
var textDate = new Date(text);
1360-
if(!isNaN(textDate.getDate())) {
1360+
var numberOnly = text.match(/^[0-9]+$/) !== null;
1361+
if(!numberOnly && !isNaN(textDate.getDate())) {
13611362
return textDate;
13621363
}
13631364
text = text.toLowerCase();

0 commit comments

Comments
 (0)