All files / utils dateUtils.jsx

100% Statements 26/26
100% Branches 14/14
100% Functions 6/6
100% Lines 23/23

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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93      2x                   2x                                                   2x 7x 5x   5x 5x 4x 5x 4x 4x 4x 6x                           5x               2x 21x 18x                 18x 18x 44x 44x 35x     18x    
import { hhmmTohhmma } from "./timeUtils";
 
// Constants
export const daysOfWeek = [
  "Monday",
  "Tuesday",
  "Wednesday",
  "Thursday",
  "Friday",
  "Saturday",
  "Sunday",
];
 
export const hours = [
  // Stryker disable all : no test needed
  "8 AM",
  "9 AM",
  "10 AM",
  "11 AM",
  "12 PM",
  "1 PM",
  "2 PM",
  "3 PM",
  "4 PM",
  "5 PM",
  "6 PM",
  "7 PM",
  "8 PM",
  "9 PM",
  "10 PM",
  // Stryker restore all
];
 
// Helper functions
/**
 * Transforms course sections data into an array of event objects for the scheduler
 * @param {Array} sections - Array of course section objects
 * @returns {Array} - Array of formatted event objects for display in the scheduler
 */
export const transformToEvents = (sections) => {
  if (!sections) return [];
  const events = [];
 
  sections.forEach((course) => {
    if (course.classSections) {
      course.classSections.forEach((classSection) => {
        if (classSection.timeLocations) {
          classSection.timeLocations.forEach((timeLocation) => {
            const days = mapDays(timeLocation.days);
            days.forEach((day) => {
              events.push({
                id: `${classSection.enrollCode}-${day}`,
                title: `${course.courseId ? course.courseId.trim() : "N/A"} (${classSection.section})`,
                description: `${course.title ? course.title : "N/A"} - ${timeLocation.building} ${timeLocation.room}`,
                day: day,
                startTime: hhmmTohhmma(timeLocation.beginTime),
                endTime: hhmmTohhmma(timeLocation.endTime),
              });
            });
          });
        }
      });
    }
  });
  return events;
};
 
/**
 * Helper function to parse days string (e.g., " T R  ") into an array of day names
 * @param {string} daysString - A string representing days (e.g., "M W F")
 * @returns {Array} - Array of full day names (e.g., ["Monday", "Wednesday", "Friday"])
 */
export const mapDays = (daysString) => {
  if (!daysString) return [];
  const dayMapping = {
    M: "Monday",
    T: "Tuesday",
    W: "Wednesday",
    R: "Thursday",
    F: "Friday",
    S: "Saturday",
    U: "Sunday",
  };
  const activeDays = [];
  for (let i = 0; i < daysString.length; i++) {
    const char = daysString[i];
    if (dayMapping[char]) {
      activeDays.push(dayMapping[char]);
    }
  }
  return activeDays;
};