react-weekly-table
Version:
React weekly scheduler <br/> By default build time ranges for a week, supports up to 31 days <br/> Can work with different timezones, data always return to UTC+0
36 lines (35 loc) • 1.32 kB
JavaScript
/**
* Timebloks merger after applying offset (for output)
* @param offsetsBlocks - array of timeblocks with applied offset
* @param columns - used day of week count
* @returns ScheduleGroups output in UTC timezone
*/
export const outputMerger = (offsetsBlocks, columns) => {
const mergedBlocks = new Array();
for (let i = 0; i < columns.length; i++) {
const columnWeight = columns[i].weight;
const columnBlocks = offsetsBlocks
.filter((ob) => ob.column === columnWeight)
.sort((prev, cur) => {
if (prev.startTime <= cur.startTime)
return -1;
return 1;
});
for (let i = 0; i < columnBlocks.length; i++) {
const current = columnBlocks[i];
const next = columnBlocks[i + 1];
if (!next) {
mergedBlocks.push(current);
break;
}
if (current.endTime !== next.startTime) {
mergedBlocks.push(current);
continue;
}
const merged = Object.assign(Object.assign({}, current), { endTime: next.endTime, realEndTime: next.realEndTime });
mergedBlocks.push(merged);
i = i + 1;
}
}
return mergedBlocks;
};