All files / src/sections/PayBuilder/Forms/DateAndLocation/components/Timers utils.ts

95.23% Statements 20/21
83.33% Branches 5/6
100% Functions 1/1
95.23% Lines 20/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41      16x 16x   16x 16x     16x 14x 14x 1344x 1344x   14x     2x 2x   2x   1x 1x     1x         2x 151x 151x     2x    
import moment from "moment";
 
export function generateTimeOptions(inputDate?: any) {
  const now = moment();
  const times = [];
 
  const startOfDay = moment().startOf("day");
  const endOfDay = moment().endOf("day");
 
  // If no inputDate is provided, generate the entire day
  if (!inputDate) {
    const currentTime = startOfDay;
    while (currentTime <= endOfDay) {
      times.push(currentTime.format("hh:mm A"));
      currentTime.add(15, "minutes");
    }
    return times;
  }
 
  const isToday = moment(inputDate).isSame(now, "day");
  let currentTime = startOfDay;
 
  if (isToday) {
    // If the date is today, start from the next 15-minute divisible interval
    const nextDivisibleMinute = Math.ceil(now.minute() / 15) * 15;
    currentTime = now.clone().minute(nextDivisibleMinute).second(0);
 
    // Ensure the time is in the future
    Iif (currentTime.isBefore(now)) {
      currentTime.add(15, "minutes");
    }
  }
 
  while (currentTime <= endOfDay) {
    times.push(currentTime.format("hh:mm A"));
    currentTime.add(15, "minutes");
  }
 
  return times;
}