From 2239f64603145ed8cab6d9b859c78b1d5fb40f0f Mon Sep 17 00:00:00 2001 From: TATSUNO Yasuhiro Date: Mon, 13 Jul 2020 06:18:00 +0900 Subject: [PATCH] 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. --- src/definitions/modules/calendar.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/definitions/modules/calendar.js b/src/definitions/modules/calendar.js index 39c1e3d86d..c971bfcc60 100644 --- a/src/definitions/modules/calendar.js +++ b/src/definitions/modules/calendar.js @@ -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();