Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 66x 66x 61x 66x 66x 66x 1x 1x 1x 1x 1x 27x 27x 27x 22x 27x 27x 1x 1x 15x 14x 14x 14x 14x 15x 15x 1x 1x 13x 13x 1x 1x 1x 1x 1x 6x 6x 6x 5x 5x 1x 1x 1x 1x 1x 9x 9x 9x | /**
* Half-time break countdown + backdated 2nd-half start (SB-1353).
*
* Pure helpers, parity with the Android app: the break is a fixed 10
* minutes from halftime_start. Once it is overdue the admin can start the
* 2nd half "at the end of the break" instead of "now".
*/
export const BREAK_MINUTES = 10;
const BREAK_MS = BREAK_MINUTES * 60 * 1000;
function toMs(value) {
if (value === null || value === undefined || value === '') return null;
const ms =
value instanceof Date ? value.getTime() : new Date(value).getTime();
return Number.isNaN(ms) ? null : ms;
}
/**
* Whole seconds left in the break; negative once overdue, null when there
* is no (valid) halftime_start.
*/
export function remainingSeconds(halftimeStart, now = Date.now()) {
const start = toMs(halftimeStart);
const nowMs = toMs(now);
if (start === null || nowMs === null) return null;
const secs = Math.ceil((start + BREAK_MS - nowMs) / 1000);
return secs === 0 ? 0 : secs; // normalise -0
}
/** "7:42" while the break runs, "+2:15" once overdue, "" for null. */
export function countdownText(remaining) {
if (remaining === null || remaining === undefined) return '';
const abs = Math.abs(remaining);
const m = Math.floor(abs / 60);
const s = abs % 60;
const text = `${m}:${String(s).padStart(2, '0')}`;
return remaining < 0 ? `+${text}` : text;
}
/** True once the 10-minute break has run out. */
export function isOverdue(remaining) {
return remaining !== null && remaining !== undefined && remaining < 0;
}
/**
* When the 2nd half most likely kicked off: the end of the break, but never
* in the future. Returns a Date, or null when there is no halftime_start.
*/
export function expectedSecondHalfStart(halftimeStart, now = Date.now()) {
const start = toMs(halftimeStart);
const nowMs = toMs(now);
if (start === null || nowMs === null) return null;
return new Date(Math.min(start + BREAK_MS, nowMs));
}
/**
* Whether backdating is worth offering: only when the end of the break is
* at least a minute in the past.
*/
export function shouldOfferBackdate(halftimeStart, now = Date.now()) {
const remaining = remainingSeconds(halftimeStart, now);
return remaining !== null && remaining <= -60;
}
|