Skip to content

Commit e72face

Browse files
committed
Revert "Block prediction updated"
This reverts commit 80442e6.
1 parent 80442e6 commit e72face

1 file changed

Lines changed: 3 additions & 57 deletions

File tree

options.js

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -450,72 +450,18 @@ function retrieveOptions() {
450450
let nearTimeLimit = false;
451451
if (useTimeLimit && checkTimeLimit) {
452452
// Lock 'X' mins early ==> Reduce time limit by 'X' mins
453-
454453
let maxUnlockTime = limitMins - blockOffset;
455-
// Time limit > lock offset: normal behaviour
454+
// Positive lock limit: normal behaviour
456455
if (maxUnlockTime > 0) {
457456
let secondsLeft = maxUnlockTime * 60;
458457
if (timedata[2] == periodStart) {
459458
secondsLeft = Math.max(0, secondsLeft - timedata[3]);
460459
}
461460
nearTimeLimit = secondsLeft <= 0;
462461
} else {
463-
// Negative lock limit: Complex* interactions between time periods/timedata/day borders
462+
// Negative lock limit: Complex* interactions with time periods/timedata/day borders
464463
// *skipped for simplicity
465-
nearTimeLimit = false;
466-
// Possible: Check if future time limit contains time period start
467-
//const midnight = new Date(timedate.getTime());
468-
//const midStamp = midnight.setHours(0, 0, 0, 0);
469-
const intersect = (a, b) => Math.max(0, Math.min(a[1], b[1]) - Math.max(a[0], b[0]));
470-
const limitSecs = limitMins * 60;
471-
const predictionCutoff = now + (blockOffset * 60);
472-
const mps = conjMode ? minPeriods : cleanTimePeriods(ALL_DAY_TIMES);
473-
474-
for(let startTP = periodStart; !nearTimeLimit && (startTP <= predictionCutoff); startTP = getTimePeriodStart(+startTP + +limitPeriod, limitPeriod, limitOffset)) {
475-
const nextTP = getTimePeriodStart(+startTP + +limitPeriod, limitPeriod, limitOffset);
476-
const startTime = Math.max(startTP, now); // Don't check the past
477-
const endTime = nextTP - 1;
478-
479-
let thisDay = new Date(startTime * 1000);
480-
let dayStart = thisDay.setHours(0, 0, 0, 0) / 1000;
481-
482-
let usedSeconds = (timedata[2] == periodStart) ? timedata[3] : 0;
483-
for(;!nearTimeLimit && (dayStart <= endTime); thisDay.setDate(thisDay.getDate() + 1)) {
484-
dayStart = thisDay.setHours(0, 0, 0, 0) / 1000;
485-
486-
for (const mp of mps) {
487-
const adjusted = {
488-
start: mp.start * 60 + dayStart,
489-
end: mp.end * 60 + dayStart
490-
}
491-
492-
493-
const activeDay = days[thisDay.getDay()];
494-
if (!activeDay || adjusted.start >= endTime)
495-
break;
496-
497-
const overlap = intersect([adjusted.start, adjusted.end], [startTime, endTime]);
498-
// Time periods MUST overlamp with block periods
499-
if (overlap > 0) {
500-
const totalUsed = usedSeconds + overlap;
501-
502-
// This MP is where locking could occur
503-
if (totalUsed >= limitSecs) {
504-
// Calc __WHEN__ lock could activate
505-
const engageTime = adjusted.start + Math.max(0, limitSecs - usedSeconds);
506-
const lockTime = engageTime - blockOffset * 60;
507-
if (now >= lockTime) {
508-
nearTimeLimit = true;
509-
break;
510-
}
511-
512-
} else {
513-
usedSeconds = totalUsed;
514-
}
515-
}
516-
}
517-
}
518-
}
464+
nearTimeLimit = true;
519465
}
520466
}
521467

0 commit comments

Comments
 (0)