From 10a380daeca82004dfd116401bdefa3c80a5813c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marker=20dao=20=C2=AE?= Date: Fri, 27 Sep 2024 14:12:29 +0200 Subject: [PATCH] refactor(date) --- packages/devextreme/js/core/utils/date.js | 25 ++++++++++------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/packages/devextreme/js/core/utils/date.js b/packages/devextreme/js/core/utils/date.js index 3ca859d4f96c..7c9dde7451c4 100644 --- a/packages/devextreme/js/core/utils/date.js +++ b/packages/devextreme/js/core/utils/date.js @@ -694,30 +694,27 @@ const getRangesByDates = (dates) => { const datesInMilliseconds = dates.map((value) => correctDateWithUnitBeginning(value, 'day').getTime()); const sortedDates = datesInMilliseconds.sort((a, b) => a - b); - const getRange = (date, dates, index) => { - const range = date === dates[index - 1] - ? [date] - : [date, dates[index - 1]]; - - return range.map((value) => dateSerialization.deserializeDate(value)); - }; - const msInDay = toMilliseconds('day'); const ranges = []; let startDate = sortedDates[0]; for(let i = 1; i <= sortedDates.length; ++i) { - const currentDate = sortedDates[i]; - const previousDate = sortedDates[i - 1]; - const isNewRange = currentDate - previousDate > msInDay; + const nextDate = sortedDates[i]; + const currentDate = sortedDates[i - 1]; + + const isNewRange = nextDate - currentDate > msInDay; if(isNewRange || i === sortedDates.length) { - const range = getRange(startDate, sortedDates, i); + const range = startDate === sortedDates[i - 1] + ? [startDate] + : [startDate, sortedDates[i - 1]]; + + const serializedRange = range.map((value) => dateSerialization.deserializeDate(value)); - ranges.push(range); + ranges.push(serializedRange); - startDate = currentDate; + startDate = nextDate; } }