Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
calculateTimeInterval = (data) => {
const startedTimes = data.map((d) => dayjs(d.startedAt));
const finishedTimes = data.map((d) => dayjs(d.finishedAt));
const minStarted = startedTimes?.length ? dayjs.min(startedTimes) : "";
const maxFinished = finishedTimes?.length ? dayjs.max(finishedTimes) : "";
const duration = dayjs.duration(maxFinished.diff(minStarted));
const diffHours = parseInt(duration.asHours());
const diffMinutes = parseInt(duration.asMinutes()) % 60;
const diffDays = parseInt(duration.asDays());
const timeObj = {
"minStarted": minStarted.format("MM/DD/YY @ hh:mm a z"),
"maxFinished": maxFinished.format("MM/DD/YY @ hh:mm a z"),
"maxHourDifference": diffHours,
"maxMinDifference": diffMinutes,
"maxDaysDifference": diffDays
};
return timeObj