File tree Expand file tree Collapse file tree 1 file changed +39
-1
lines changed
Expand file tree Collapse file tree 1 file changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -332,9 +332,47 @@ function getCurrentClassPeriodIndex() {
332332 break ; //not sure if this is necessary so I included it anyway
333333 }
334334 }
335- return - 1
335+ return - 1 //no match found, there is no class currently in session
336+ }
337+
338+
339+
340+ /**
341+ *
342+ *
343+ * @returns the index of the class that started most recently
344+ */
345+ function getMostRecentlyStartedClassIndex ( ) {
346+
347+ if ( isNoSchoolDay ( ) ) {
348+ //return immediately if there is no school today
349+ return - 1
350+ }
351+
352+
353+ //using for over forEach() because we are breaking out of the loop early
354+ for ( let i = 0 ; i < schools [ selectedSchoolIndex ] . schedules [ currentScheduleIndex ] . classes . length ; i ++ ) {
355+ let classPeriodStatus = checkClassTime ( schools [ selectedSchoolIndex ] . schedules [ currentScheduleIndex ] . classes [ i ] )
356+ let nextClassPeriodStatus ;
357+ if ( i + 1 < schools [ selectedSchoolIndex ] . schedules [ currentScheduleIndex ] . classes . length ) {
358+ nextClassPeriodStatus = checkClassTime ( schools [ selectedSchoolIndex ] . schedules [ currentScheduleIndex ] . classes [ i + 1 ] )
359+ }
360+
361+ if ( classPeriodStatus == - 1 ) {
362+ //class hasnt started, do nothing
363+ } else if ( classPeriodStatus == 0 ) {
364+ //class is currently in session, return index
365+ return i
366+ } else if ( classPeriodStatus == 1 && ( typeof nextClassPeriodStatus !== "undefined" && nextClassPeriodStatus == - 1 ) ) {
367+ //class has passed and next class hasnt started (indicating a passing period)
368+ //return the class index
369+ return i
370+ }
371+ }
372+
336373}
337374
375+
338376/**
339377 * this function determines the index of the schedule that applies to today (if any)
340378 *
You can’t perform that action at this time.
0 commit comments