Skip to content

Commit

Permalink
refactor(date)
Browse files Browse the repository at this point in the history
  • Loading branch information
marker dao ® committed Sep 27, 2024
1 parent e6875c2 commit 10a380d
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions packages/devextreme/js/core/utils/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 10a380d

Please sign in to comment.