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
29 lines (28 loc) • 1.08 kB
JavaScript
/**
* Schedule groups parser with setting offset
* @param defaultValue - input groups
* @param columnsLength - used day of week count
* @param tzOffset - required offset in ms
* @returns Timeblocks with offset
*/
export const inputParser = (defaultValue, columnsLength, tzOffset) => {
return defaultValue.reduce((acc, current) => {
let binMask = current.mask.toString(2);
if (binMask.length < columnsLength) {
binMask = '0'.repeat(columnsLength - binMask.length).concat(binMask);
}
const inputColumns = [...binMask].reverse();
const ofStart = current.startTime - tzOffset;
const ofEnd = current.endTime - tzOffset;
const filtered = inputColumns.reduce((acc, current, currentIndex) => {
if (current === '0')
return acc.concat();
return acc.concat({
startTime: ofStart,
endTime: ofEnd,
column: currentIndex,
});
}, []);
return acc.concat(filtered);
}, []);
};