All files / utils sectionUtils.js

100% Statements 50/50
100% Branches 16/16
100% Functions 9/9
100% Lines 46/46

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 94 95 96 97 98    12x 867x       12x 867x 867x 867x 811x 811x 1x     866x   1x         12x 863x 863x 863x 808x       808x       1x     862x   1x         12x 867x 867x 867x 811x       811x 1x     866x   1x         12x 867x 867x 867x 860x 860x 14x     866x   1x         12x 446x       12x 464x       12x 476x     12x 862x    
import { hhmmTohhmma, convertToTimeRange } from "main/utils/timeUtils.js";
 
export const convertToFraction = (en1, en2) => {
  return en1 != null && en2 != null ? `${en1}/${en2}` : "";
};
 
// Takes a time location array and returns the locations
export const formatLocation = (timeLocationArray) => {
  try {
    let res = "";
    for (let index = 0; index < timeLocationArray.length; index++) {
      res += `${timeLocationArray[index].building} ${timeLocationArray[index].room}`;
      if (index + 1 < timeLocationArray.length) {
        res += `, `;
      }
    }
    return res;
  } catch {
    return "";
  }
};
 
// Takes a time location array and returns the days
export const formatDays = (timeLocationArray) => {
  try {
    let res = "";
    for (let index = 0; index < timeLocationArray.length; index++) {
      res +=
        timeLocationArray[index].days !== null
          ? `${timeLocationArray[index].days}`
          : "";
      if (
        index + 1 < timeLocationArray.length &&
        timeLocationArray[index].days !== null
      ) {
        res += `, `;
      }
    }
    return res;
  } catch {
    return "";
  }
};
 
// Takes a time location array and returns the time range
export const formatTime = (timeLocationArray) => {
  try {
    let res = "";
    for (let index = 0; index < timeLocationArray.length; index++) {
      res += convertToTimeRange(
        hhmmTohhmma(timeLocationArray[index].beginTime),
        hhmmTohhmma(timeLocationArray[index].endTime),
      );
      if (index + 1 < timeLocationArray.length) {
        res += `, `;
      }
    }
    return res;
  } catch {
    return "";
  }
};
 
// Takes a instructors array and returns the instructors
export const formatInstructors = (instructorArray) => {
  try {
    let res = "";
    for (let index = 0; index < instructorArray.length; index++) {
      res += `${instructorArray[index].instructor}`;
      if (index + 1 < instructorArray.length) {
        res += `, `;
      }
    }
    return res;
  } catch {
    return "";
  }
};
 
// Takes an entire section row and returns whether the section is full
export const isSectionFull = (section) => {
  return section.enrolledTotal >= section.maxEnroll;
};
 
// Takes an entire section row and returns whether the section is closed
export const isSectionClosed = (section) => {
  return section.classClosed !== null;
};
 
// Takes an entire section row and returns whether the section is cancelled
export const isSectionCancelled = (section) => {
  return section.courseCancelled !== null;
};
 
export const isSection = (en1) => {
  return en1.substring(2) !== "00";
};