//Takes a Date object
//Returns an integer number representing the number of weeks
//of a month
const getWeeksOfMonth = day => {
  const firstDay = new Date(day.setDate(1)).getDay()
  const totalDays = new Date(day.getFullYear(), day.getMonth() + 1, 0).getDate()
  return Math.ceil((firstDay + totalDays) / 7)
}

//Returns an integer number representing the week of the month
//depending on the selected day
const getWeekOfMonth = (year, month, day) => {
  const firstWeekday = new Date(year, month, 1).getDay()
  const d = new Date(year, month, day)
  const offsetDate = d.getDate() + firstWeekday - 1
  return Math.floor(offsetDate / 7) + 1
}


const getWeekDateRange = (month, year, weekNumber) => {
  const day = new Date(year, month, 1)
  const weeksOfMonth = getWeeksOfMonth(day)
  const startDay = day.getDay()
  let daysInMonth = new Date(year, month + 1, 0)
  daysInMonth = daysInMonth.getDate()
  let firstNum, endNum

  if (weekNumber === 1) {
    firstNum = 1
    endNum = 7 - startDay
  } else if (weekNumber === weeksOfMonth) {
    firstNum = 7 * (weeksOfMonth - 2) + (7 - startDay) + 1
    endNum = daysInMonth
  } else {
    firstNum = 7 * (weekNumber - 1) - startDay + 1
    endNum = firstNum + 6
  }

  if (firstNum === endNum) {
    return firstNum
  }
  return firstNum + " - " + endNum
}


const getStartOfWeek = (month, year, weekNumber) => {
  const day = new Date(year, month, 1)
  const weeksOfMonth = getWeeksOfMonth(day)
  const startDay = day.getDay()
  let daysInMonth = new Date(year, month + 1, 0)
  daysInMonth = daysInMonth.getDate()
  let firstNum

  if (weekNumber === 1) {
    firstNum = 1
  } else if (weekNumber === weeksOfMonth) {
    firstNum = 7 * (weeksOfMonth - 2) + (7 - startDay) + 1
  } else {
    firstNum = 7 * (weekNumber - 1) - startDay + 1
  }

  return firstNum 
}


const getWeekArray = (month, year, weekNumber) => {
  const daysInMonth = new Date(year, month + 1, 0)
  const lastMonth = new Date(year, month, 0)
  const day = new Date(year, month, 1)
  const weeksOfMonth = getWeeksOfMonth(day)
  const startDay = day.getDay()
  let firstDay, endDay
  let weekArray = []

    if (weekNumber === 1){
      endDay = 7 - startDay 
      firstDay = lastMonth.getDate() + 1 - startDay
      
      for (let i = 0; i < 7; i++){
        if (i < startDay){
          weekArray[i] = {month: (month - 1), day: (firstDay + i)}
        }else{
          weekArray[i] = {month: month, day: (1 + (i - startDay))}
        }
      }
    }else if (weekNumber === weeksOfMonth){
      firstDay = 7 * (weeksOfMonth - 2) + (7 - startDay) + 1
      endDay = 7 - daysInMonth.getDay()

      for (let i = 0; i < 7; i++){
        if (i <= daysInMonth.getDay()){
          weekArray[i] = {month: (month), day: (firstDay + i)}
        }else{
          weekArray[i] = {month: (month + 1), day: (endDay - (i - daysInMonth.getDay()))}
        }
      }
    }else{
      firstDay = 7 * (weekNumber - 1) - startDay + 1
      for (let i = 0; i < 7; i++){
        weekArray[i] = {month: (month), day: (firstDay + i)}
      }
    }
    return weekArray
}

export { getWeekOfMonth, getWeeksOfMonth, getWeekDateRange, getStartOfWeek, getWeekArray }

@@ -3069,16 +3069,348 @@
 rray%0A%7D%0A%0A
+const getMilitaryTime = (timeString) =%3E %7B%0A  const splitArray = timeString.split(%22:%22)%0A  let hours = parseInt(splitArray%5B0%5D)%0A  const minutes = splitArray%5B1%5D.substring(0, 2)%0A  let afternoon = false%0A%0A  if (splitArray%5B1%5D.substring(2, 3) == %22p%22)%7B%0A    afternoon = true%0A    hours += 12%0A  %7D%0A  return (%7Bhours: hours, minutes: minutes%7D)%0A  %0A%7D%0A%0A
 export %7B
@@ -3489,11 +3489,28 @@
 eekArray
+, getMilitaryTime
  %7D%0A

Converts backend code to military time #5