Home: an einem Ruhetag steht dort, wann die naechste Einheit ist

Die Today-Zeile war an einem Ruhetag eine Sackgasse: "Pausentag", Punkt. Die
Antwort auf die naechstliegende Frage — wann dann? — steht schon im State, nur
hat sie nie jemand ausgesprochen.

nextTrainingDay() sitzt neben effectiveRoutine und schaut ab morgen sieben Tage
voraus. Es nimmt ein ISO-Datum statt die Uhr zu lesen, damit Aufrufer und Tests
sich einig sind, was "heute" ist. Ein Tag mit einer Routine ohne Uebungen zaehlt
nicht: den zu starten landet in einer leeren Session, ist also keine Antwort
(dieselbe Bedingung, die auch die TabBar vor dem Start prueft). Verschiebungen
aus dayPlan gelten in beide Richtungen — ein auf 'rest' gesetzter Tag faellt
raus, ein per Datum eingeplanter kommt rein. Ist die ganze Woche Pause: null,
und die Zeile bleibt wie sie war.

Angezeigt nur, wenn heute wirklich nichts ansteht — kein laufendes Training,
keine Routine, kein schon erledigtes Training. Strings in allen vierzehn
Sprachen, pt-BR-Fingerabdruck nachgezogen.
This commit is contained in:
Duarte Santos committed 2026-09-01 14:13:36 +02:00
1 parent 45c4756cd0
commit ddaaf12929
17 files changed
+90 -5

No files matched your search

+19
View File
@@ -284,6 +284,25 @@ export function effectiveRoutine(S, iso) {
const id = effectiveRoutineId(S, iso)
return id ? S.routines.find(r => r.id === id) || null : null
}
/**
* The next day that actually has something to train, looking forward from `iso` (exclusive).
*
* Takes a date string rather than reading the clock so callers and tests agree on "today".
* A routine with no exercises does not count: starting one lands you in an empty session, so
* it is not an answer to "what is next" (the same guard TabBar applies before starting).
* Returns null when the whole week is rest.
*/
export function nextTrainingDay(S, iso) {
for (let i = 1; i <= 7; i++) {
const d = new Date(iso + 'T12:00:00')
d.setDate(d.getDate() + i)
const nextIso = isoOf(d)
const routine = effectiveRoutine(S, nextIso)
if (routine && (routine.ex || []).length) return { iso: nextIso, weekday: d.getDay(), routine }
}
return null
}
/**
* Build the rows a planned exercise starts a session with: its work sets, preceded by however
* many warm-up sets the routine asks for (`cfg.warmupSets`, 0 by default so an existing plan
+51 -1
View File
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
import { modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, freestyleConfig, exLine, workoutVolume, bestWeightFor, bestWeightForEntry, effortOf, stepEffort, capEffort, isBw, isPerSide, sideReps, repStep, cascadeWeight, insertWarmupRow, removeRowAt, workSetsDone, pairAdjacent, unpairSuperset, supersetUnits, applyIntensifierPlan, pinnedNoteFor, exNoteFor } from './history.js'
import { nextTrainingDay, modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, freestyleConfig, exLine, workoutVolume, bestWeightFor, bestWeightForEntry, effortOf, stepEffort, capEffort, isBw, isPerSide, sideReps, repStep, cascadeWeight, insertWarmupRow, removeRowAt, workSetsDone, pairAdjacent, unpairSuperset, supersetUnits, applyIntensifierPlan, pinnedNoteFor, exNoteFor } from './history.js'
import { EXDB } from './exercises.js'
// Real ids out of the shipped catalogue, so the body-part fallback is exercised for real.
@@ -853,3 +853,53 @@ describe('exNoteFor', () => {
expect(exNoteFor({}, '0025')).toBeNull()
})
})
describe('nextTrainingDay', () => {
// 2026-08-18 is a Tuesday; the week map is keyed by getDay(), so 0 is Sunday.
const TUE = '2026-08-18'
const base = (over = {}) => ({
dayPlan: {},
routines: [{ id: 'r1', name: 'A', ex: [{ id: '0001' }] }, { id: 'r2', name: 'B', ex: [{ id: '0002' }] }],
week: {},
...over
})
it('finds the next scheduled day and names its routine', () => {
const S = base({ week: { 4: 'r2' } }) // Thursday
expect(nextTrainingDay(S, TUE)).toMatchObject({ iso: '2026-08-20', weekday: 4 })
expect(nextTrainingDay(S, TUE).routine.name).toBe('B')
})
it('looks forward only — today itself is never the answer', () => {
// Only Tuesday is scheduled and today is Tuesday, so the next one is a week out. (The UI
// cannot reach this: a day with a session takes the other branch and never asks.)
const S = base({ week: { 2: 'r1' } })
expect(nextTrainingDay(S, TUE)).toMatchObject({ iso: '2026-08-25', weekday: 2 })
})
it('wraps around the end of the week', () => {
const S = base({ week: { 1: 'r1' } }) // Monday, six days on
expect(nextTrainingDay(S, TUE)).toMatchObject({ iso: '2026-08-24', weekday: 1 })
})
it('is null when every day is rest', () => {
expect(nextTrainingDay(base(), TUE)).toBeNull()
})
it('skips a day whose routine no longer exists', () => {
const S = base({ week: { 3: 'gone', 5: 'r1' } })
expect(nextTrainingDay(S, TUE)).toMatchObject({ iso: '2026-08-21', weekday: 5 })
})
it('skips a routine with no exercises — starting it would open an empty session', () => {
const S = base({ routines: [{ id: 'r1', name: 'A', ex: [] }, { id: 'r2', name: 'B', ex: [{ id: '1' }] }], week: { 3: 'r1', 5: 'r2' } })
expect(nextTrainingDay(S, TUE)).toMatchObject({ weekday: 5 })
})
it('respects a per-date override in both directions', () => {
const moved = base({ week: {}, dayPlan: { '2026-08-19': 'r1' } })
expect(nextTrainingDay(moved, TUE)).toMatchObject({ iso: '2026-08-19' })
const off = base({ week: { 3: 'r1', 5: 'r2' }, dayPlan: { '2026-08-19': 'rest' } })
expect(nextTrainingDay(off, TUE)).toMatchObject({ weekday: 5 })
})
})
+2 -2
View File
@@ -28,10 +28,10 @@ describe('Brazilian Portuguese locale', () => {
const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex')
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(342)
expect(inherited).toHaveLength(461)
expect(inherited).toHaveLength(462)
// If this fails, review the changed keys and wording before accepting a new hash. From
// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('1b6f52ab4152f95d7fca75fb79f12f582be228f6388b292b75932bfd09b427b2')
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('1ee637df4fe0a6e4bf56c5d728981ebd713147b23886b1ee533f1e6d18ec59bb')
})
test('does not leak European Portuguese UI terms', () => {