 <script>
  $(document).ready(function () {
    console.log("Begin Fellowship Cohort Script")

    $(".fellowship-course").css("display", "none")

    // Release time is set as 14:00 UTC (9am eastern time)
    let courseReleaseHour = Number({{ course_release_hour }})

    let fellowship_enrollment_year = new Date(Number('{{ fellowship_enrollment_date | date: "%s" }}') * 1000).getFullYear()
    let fellowship_enrollment_month = new Date(Number('{{ fellowship_enrollment_date | date: "%s" }}') * 1000).getMonth() + 1

    let cohortStartDate = ''
    console.log(`Fellowship Cohort Enrollment date: ${fellowship_enrollment_month}, ${fellowship_enrollment_year}`)  

    if (fellowship_enrollment_month >= 1 && fellowship_enrollment_month <=2 ) {

      cohortStartDate = new Date(Date.UTC(fellowship_enrollment_year, 0, 1, courseReleaseHour, 00 ))
      releaseJanCohortCourses(cohortStartDate, courseReleaseHour, fellowship_enrollment_year)

    }  else if (fellowship_enrollment_month >= 9 && fellowship_enrollment_month <=12 ) {

      cohortStartDate = new Date(Date.UTC(fellowship_enrollment_year + 1, 0, 1, courseReleaseHour, 00))
      releaseJanCohortCourses(cohortStartDate, courseReleaseHour, fellowship_enrollment_year + 1)

    } else if (fellowship_enrollment_month >= 3 && fellowship_enrollment_month <=8 ) {

      cohortStartDate = new Date(Date.UTC(fellowship_enrollment_year, 6, 1, courseReleaseHour - 1, 00))
      releaseJulCohortCourses(cohortStartDate, courseReleaseHour, fellowship_enrollment_year)

    }

    function releaseJanCohortCourses(cohortStartDate, releaseHour, year) {
      console.log("Your Cohort Will Begin: ", cohortStartDate)
      let now = new Date()

      let febStart = new Date(Date.UTC(year, 1, 1, courseReleaseHour, 00 ))
      let marStart = new Date(Date.UTC(year, 2, 1, courseReleaseHour, 00 ))
      let aprStart = new Date(Date.UTC(year, 3, 1, courseReleaseHour, 00 ))
      let mayStart = new Date(Date.UTC(year, 4, 1, courseReleaseHour, 00 ))
      let junStart = new Date(Date.UTC(year, 5, 1, courseReleaseHour, 00 ))
      let julStart = new Date(Date.UTC(year, 6, 1, courseReleaseHour, 00 ))
      let augStart = new Date(Date.UTC(year, 7, 1, courseReleaseHour, 00 ))
      let sepStart = new Date(Date.UTC(year, 8, 1, courseReleaseHour, 00 ))
      let octStart = new Date(Date.UTC(year, 9, 1, courseReleaseHour, 00 ))
      let novStart = new Date(Date.UTC(year, 10, 1, courseReleaseHour, 00 ))
      let decStart = new Date(Date.UTC(year, 11, 1, courseReleaseHour, 00 ))

      //console.log("Current Date and Time: ", now)

      if ( now >= cohortStartDate ) {
        console.log("Cohort Started")

        $(".module-1").css("display", "block")

        if (now >= febStart ) {
          console.log("show module 2")
          $(".module-2").css("display", "block")
        } 
        
        if (now >= marStart ) {
          console.log("show module 3")
          $(".module-3").css("display", "block")
        } 
        
        if (now >= aprStart ) {
          console.log("show module 4")
          $(".module-4").css("display", "block")
        } 
        
        if (now >= mayStart ) {
          console.log("show module 5")
          $(".module-5").css("display", "block")
        } 
        
        if (now >= junStart ) {
          console.log("show module 6")
          $(".module-6").css("display", "block")
        } 
        
        if (now >= julStart ) {
          console.log("show module 7")
          $(".module-7").css("display", "block")
        } 
        
        if (now >= augStart ) {
          console.log("show module 8")
          $(".module-8").css("display", "block")
        } 
        
        if (now >= sepStart ) {
          console.log("show module 9")
          $(".module-9").css("display", "block")
        } 
        
        if (now >= octStart ) {
          console.log("show module 10")
          $(".module-10").css("display", "block")
        } 
        
        if (now >= novStart ) {
          console.log("show module 11")
          $(".module-11").css("display", "block")
        } 
        
        if (now >= decStart ) {
          console.log("show module 12")
          $(".module-12").css("display", "block")
        }

      } else {
        console.log("Your Jan Cohort has not yet Started")
      }
    }

    function releaseJulCohortCourses(cohortStartDate, releaseHour, year) {
      console.log("Your Cohort Will Begin: ", cohortStartDate)
      let now = new Date()

      let augStart = new Date(Date.UTC(year, 7, 1, courseReleaseHour - 1, 00 ))
      let sepStart = new Date(Date.UTC(year, 8, 1, courseReleaseHour - 1, 00 ))
      let octStart = new Date(Date.UTC(year, 9, 1, courseReleaseHour - 1, 00 ))
      let novStart = new Date(Date.UTC(year, 10, 1, courseReleaseHour - 1, 00 ))
      let decStart = new Date(Date.UTC(year, 11, 1, courseReleaseHour, 00 ))
      let janStart = new Date(Date.UTC(year + 1, 0, 1, courseReleaseHour, 00 ))
      let febStart = new Date(Date.UTC(year + 1, 1, 1, courseReleaseHour, 00 ))
      let marStart = new Date(Date.UTC(year + 1, 2, 1, courseReleaseHour, 00 ))
      let aprStart = new Date(Date.UTC(year + 1, 3, 1, courseReleaseHour - 1, 00 ))
      let mayStart = new Date(Date.UTC(year + 1, 4, 1, courseReleaseHour - 1, 00 ))
      let junStart = new Date(Date.UTC(year + 1, 5, 1, courseReleaseHour - 1, 00 ))

      // console.log("Current Date and Time: ", now)

      if ( now >= cohortStartDate ) {
        console.log("July Cohort Started")

        $(".module-1").css("display", "block")

        if (now >= augStart ) {
          console.log("show module 2")
          $(".module-2").css("display", "block")
        } 
        
        if (now >= sepStart ) {
               console.log("show module 3")
          $(".module-3").css("display", "block")
        } 
        
        if (now >= octStart ) {
          console.log("show module 4")
          $(".module-4").css("display", "block")
        } 
        
        if (now >= novStart ) {
          console.log("show module 5")
          $(".module-5").css("display", "block")
        } 
        
        if (now >= decStart ) {
          console.log("show module 6")
          $(".module-6").css("display", "block")
        }

        if (now >= janStart ) {
          console.log("show module 7")
          $(".module-7").css("display", "block")
        }

        if (now >= febStart ) {
          console.log("show module 8")
          $(".module-8").css("display", "block")
        } 
        
        if (now >= marStart ) {
          console.log("show module 9")
          $(".module-9").css("display", "block")
        } 
        
        if (now >= aprStart ) {
          console.log("show module 10")
          $(".module-10").css("display", "block")
        } 
        
        if (now >= mayStart ) {
          console.log("show module 11")
          $(".module-11").css("display", "block")
        } 
        
        if (now >= junStart ) {
          console.log("show module 12")
          $(".module-12").css("display", "block")
        } 

      } else {
        console.log("July Cohort not yet Started")
      }
    
    }
  });
</script>