| 1088 | } |
| 1089 | |
| 1090 | function secondsUntilNextProgram() { |
| 1091 | if ( logLevel >= 2 ) console.log( "secondsUntilNextProgram()" ); |
| 1092 | |
| 1093 | let now = new Date(); |
| 1094 | let minutesAhead = -1; |
| 1095 | let matchingCron = false; |
| 1096 | |
| 1097 | timeLoop : do { |
| 1098 | minutesAhead++; |
| 1099 | |
| 1100 | if ( logLevel >= 2 ) console.log( "Checking " + minutesAhead + " minutes ahead" ); |
| 1101 | |
| 1102 | let adjustedTime = new Date( now.valueOf() + ( minutesAhead * 60 * 1000 ) ); |
| 1103 | |
| 1104 | for ( let cron in programming.schedule ) { |
| 1105 | if ( cron.indexOf( '* ' ) === 0 ) { |
| 1106 | if ( logLevel >= 2 ) console.log( "Skipping cron " + cron ); |
| 1107 | continue; |
| 1108 | } |
| 1109 | |
| 1110 | if ( Cron.timeMatchesCron( adjustedTime, cron ) ) { |
| 1111 | if ( minutesAhead == 0 && tvElement.currentTime < 60 ) { |
| 1112 | // This is actually matching the same cron that started the current program. |
| 1113 | // Usually, we won't be looking for the next program within the same minute |
| 1114 | // that the existing program started, but we do during testing. |
| 1115 | if ( logLevel >= 2 ) console.log( "Found a matching cron, but it's for the current program: " + cron ); |
| 1116 | } else { |
| 1117 | if ( logLevel >= 2 ) console.log( "Found matching cron: " + cron, programming.schedule[cron] ); |
| 1118 | |
| 1119 | break timeLoop; |
| 1120 | } |
| 1121 | } |
| 1122 | } |
| 1123 | } while ( ! matchingCron && minutesAhead < 24 * 60 ); |
| 1124 | |
| 1125 | return Math.max( 0, ( minutesAhead * 60 ) - now.getSeconds() ); |
| 1126 | } |
| 1127 | |
| 1128 | /** |
| 1129 | * Resize various elements when the screen is resized (and when it's loaded). |