Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
api: a queue without startsOn starts on the day of the apply where the USER is (reminder.tz), not the UTC date
Boris Kurktchievfdbf5ee6b18f
diff --git a/api/queue.js b/api/queue.jsindex 374372f4a..d453495d3 100644--- a/api/queue.js+++ b/api/queue.js@@ -34,13 +34,25 @@ function queueDone(S, id, startsOn) {return (S.workouts || []).some(w => routineIdsOf(w).includes(id)&& ((w.start ?? 0) >= S.queue.since || (String(w.d || '') >= startsOn && nameParts(w).includes(currentName))));}+// The calendar date of an instant where the USER is. The frontend's fallback for a missing+// startsOn is the device's local date of the apply; the closest thing here is the zone the+// reminder already fires by (S.reminder.tz), so the two copies name the same day. UTC when the+// zone is unset or invalid (Intl throws on an unknown zone).+function dayIn(ms, tz) {+ try {+ const parts = new Intl.DateTimeFormat('en-CA', { timeZone: tz || 'UTC', year: 'numeric', month: '2-digit', day: '2-digit' }).formatToParts(new Date(ms));+ const g = t => parts.find(x => x.type === t)?.value;+ return `${g('year')}-${g('month')}-${g('day')}`;+ } catch { return new Date(ms).toISOString().slice(0, 10); }+}// Tolerant reader, as in the frontend: a missing or malformed queue reads as none. A missing-// startsOn means active now; a session whose routine was deleted is dropped from the week (the-// frontend's queue.js does the same — it could never be started or logged).+// startsOn means active since the day of the apply (dayIn above); a session whose routine was+// deleted is dropped from the week (the frontend's queue.js does the same — it could never be+// started or logged).function queueOf(S) {const q = S.queue;if (!q || typeof q !== 'object' || !Array.isArray(q.ids)) return null;- const startsOn = typeof q.startsOn === 'string' ? q.startsOn : new Date(q.since || 0).toISOString().slice(0, 10);+ const startsOn = typeof q.startsOn === 'string' ? q.startsOn : dayIn(q.since || 0, S.reminder?.tz);const ids = q.ids.filter(id => (S.routines || []).some(r => r?.id === id));return { ids, startsOn };}diff --git a/api/test/queue.test.js b/api/test/queue.test.jsindex 0fcf42bdc..3219875c6 100644--- a/api/test/queue.test.js+++ b/api/test/queue.test.js@@ -207,3 +207,21 @@ test('pins: with every remaining session pinned to other days, a coach pointer oconst complete = P({ workouts: [done('r1'), done('r2'), done('r3')], week: { 3: ['r2', 'own'] } });assert.equal(effectiveRoutineId(complete, TODAY), 'r2');});++test('a queue without startsOn starts on the day of the apply where the USER is (reminder.tz), UTC when unset or invalid', () => {+ // 02:00Z on the 9th is still the evening of the 8th in New York: the app on that phone shows+ // the session on the 8th, so the reminder must too.+ const since = Date.UTC(2026, 8, 9, 2, 0, 0);+ const q = { ids: ['r1'], since, label: 'W1' };+ assert.equal(effectiveRoutineId({ ...base, queue: q, reminder: { tz: 'America/New_York' } }, '2026-09-08'), 'r1');+ assert.equal(effectiveRoutineId({ ...base, queue: q, reminder: { tz: 'UTC' } }, '2026-09-08'), null);+ assert.equal(effectiveRoutineId({ ...base, queue: q, reminder: { tz: 'UTC' } }, '2026-09-09'), 'r1');+ assert.equal(effectiveRoutineId({ ...base, queue: q }, '2026-09-08'), null); // no reminder settings: UTC+ assert.equal(effectiveRoutineId({ ...base, queue: q, reminder: { tz: 'Mars/Olympus' } }, '2026-09-08'), null); // unknown zone: UTC, no throw+ // East of Greenwich the other way round: 23:00Z on the 8th is already the 9th in Tokyo.+ const late = { ids: ['r1'], since: Date.UTC(2026, 8, 8, 23, 0, 0), label: 'W1' };+ assert.equal(effectiveRoutineId({ ...base, queue: late, reminder: { tz: 'Asia/Tokyo' } }, '2026-09-08'), null);+ assert.equal(effectiveRoutineId({ ...base, queue: late, reminder: { tz: 'Asia/Tokyo' } }, '2026-09-09'), 'r1');+ // An explicit startsOn is never second-guessed.+ assert.equal(effectiveRoutineId({ ...base, queue: { ...q, startsOn: '2026-09-10' }, reminder: { tz: 'America/New_York' } }, '2026-09-09'), null);+});