Sindbad~EG File Manager

Current Path : /home/infinitibizsol/autocrm.infinitibizsol.com/constants/
Upload File :
Current File : /home/infinitibizsol/autocrm.infinitibizsol.com/constants/formatTimeRange.js

function formatTimeRange(timeRange) {
  let fotmttedTimeRange;
  fotmttedTimeRange = timeRange.replace(/\s/g, "");
  fotmttedTimeRange = timeRange.toLowerCase();
  return fotmttedTimeRange;
}
function calculateDateRange(timeRange) {
  const currentDate = new Date();

  switch (timeRange) {
    case "currentweek":
      const currentWeekStartDate = new Date(currentDate);
      currentWeekStartDate.setDate(
        currentDate.getDate() - currentDate.getDay()
      );
      currentWeekStartDate.setHours(0, 0, 0, 0);

      const currentWeekEndDate = new Date(currentDate);
      currentWeekEndDate.setDate(
        currentWeekEndDate.getDate() + (6 - currentWeekEndDate.getDay())
      );
      currentWeekEndDate.setHours(23, 59, 59, 999);

      return { startDate: currentWeekStartDate, endDate: currentWeekEndDate };

    case "lastweek":
      const lastWeekStartDate = new Date(currentDate);
      lastWeekStartDate.setDate(
        lastWeekStartDate.getDate() - lastWeekStartDate.getDay() - 7
      );
      lastWeekStartDate.setHours(0, 0, 0, 0);

      const lastWeekEndDate = new Date(currentDate);
      lastWeekEndDate.setDate(
        lastWeekEndDate.getDate() - lastWeekEndDate.getDay() - 1
      );
      lastWeekEndDate.setHours(23, 59, 59, 999);

      return { startDate: lastWeekStartDate, endDate: lastWeekEndDate };

    case "last4weeks":
      const last4WeeksStartDate = new Date(currentDate);
      last4WeeksStartDate.setDate(last4WeeksStartDate.getDate() - 28);
      last4WeeksStartDate.setHours(0, 0, 0, 0);

      const last4WeeksEndDate = new Date(currentDate);
      last4WeeksEndDate.setDate(last4WeeksEndDate.getDate());
      last4WeeksEndDate.setHours(23, 59, 59, 999);

      return { startDate: last4WeeksStartDate, endDate: last4WeeksEndDate };
    case "last12weeks":
      const last12WeeksStartDate = new Date(currentDate);
      last12WeeksStartDate.setDate(last12WeeksStartDate.getDate() - 84);
      last12WeeksStartDate.setHours(0, 0, 0, 0);

      const last12WeeksEndDate = new Date(currentDate);
      last12WeeksEndDate.setDate(last12WeeksEndDate.getDate());
      last12WeeksEndDate.setHours(23, 59, 59, 999);

      return { startDate: last12WeeksStartDate, endDate: last12WeeksEndDate };

    default:
      // Handle other cases or return an error
      return null;
  }
}
module.exports = { formatTimeRange, calculateDateRange };

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists