feat(epg): add global EPG display time offset (#1489)

Adds a global EPG display-time offset (Settings → EPG, whole minutes, ±720) for guides whose provider labels programme times with the wrong timezone. Display-only: parsed XMLTV values, SQLite rows, catch-up URLs and recording snapshots keep the provider's own times, so changing it needs no guide refresh. Closes the global part of #50.

The contract lives in `libs/shared/interfaces/src/lib/epg-display-offset.util.ts` with two equivalent forms: `epgDisplayTimeMs` shifts a programme for display, `epgProviderClockMs` shifts "now" into the provider's clock for every "currently airing" decision — the batched `GET_CURRENT_PROGRAMS_BATCH` lookup takes an explicit `nowMs`, and the channel lists, the Xtream/Stalker previews, the M3U player's current-programme mirror, the unified collection resolver, the dashboard live cards and the recording overlap all pick the same programme the guide renders as "now". Portal short-EPG windows start at the provider's own "now", so under a non-zero offset the Xtream preview surfaces cut their window from the full guide at the provider clock, Stalker short-EPG requests are widened for negative offsets, and every per-stream memory of the previous offset is retired together when the setting changes.

Co-authored-by: Mark Jardine <markjardine27@gmail.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-09-04 18:46:10 +02:00
1 parent b2ca85172c
commit d8d36476e6
118 files changed
+3349 -352

No files matched your search

@@ -581,6 +581,39 @@ test.describe('Electron Settings', () => {
}
});
test('@settings @persistence @electron persists the EPG display offset across app restart', async ({
dataDir,
}) => {
const firstLaunch = await launchElectronApp(dataDir);
try {
await openSettings(firstLaunch.mainWindow);
await openSettingsSection(firstLaunch.mainWindow, 'epg');
const offsetInput = firstLaunch.mainWindow.locator(
'[data-test-id="epg-offset-minutes"]'
);
await expect(offsetInput).toHaveValue('0');
await offsetInput.fill('-90');
await saveSettings(firstLaunch.mainWindow);
} finally {
await closeElectronApp(firstLaunch);
}
const secondLaunch = await launchElectronApp(dataDir);
try {
await openSettings(secondLaunch.mainWindow);
await openSettingsSection(secondLaunch.mainWindow, 'epg');
await expect(
secondLaunch.mainWindow.locator(
'[data-test-id="epg-offset-minutes"]'
)
).toHaveValue('-90');
} finally {
await closeElectronApp(secondLaunch);
}
});
test('@settings @electron starts on sources when dashboard is disabled', async ({ dataDir }) => {
const firstLaunch = await launchElectronApp(dataDir);
@@ -291,6 +291,95 @@ test('@radio @stalker @electron keeps radio rows compact at narrow widths', asyn
}
});
test('@epg @xtream @electron shifts the sidebar preview and the timeline "now" block by the EPG display offset', async ({
dataDir,
request,
}) => {
await resetMockServers(request, ['xtream']);
const fixture = await fetchXtreamEpgFixture(request, epgCredentials);
const offsetMinutes = 60;
// The guide runs an hour ahead of the real schedule, so the programme
// actually on air is the one the provider files under "an hour ago" —
// and every surface must agree on that same programme.
const providerNowSeconds = Math.floor(Date.now() / 1000) - offsetMinutes * 60;
const expectedProgram = fixture.fullEpg.find(
(listing) =>
listing.startTimestamp <= providerNowSeconds &&
providerNowSeconds < listing.stopTimestamp
);
if (!expectedProgram) {
throw new Error(
'Expected the Xtream EPG fixture to cover the shifted current time.'
);
}
const app = await launchElectronApp(dataDir, { env: { TZ: 'UTC' } });
try {
await openSettings(app.mainWindow);
await openSettingsSection(app.mainWindow, 'epg');
await app.mainWindow
.locator('[data-test-id="epg-offset-minutes"]')
.fill(String(offsetMinutes));
await saveSettings(app.mainWindow);
await goToDashboard(app.mainWindow);
await addXtreamPortal(app.mainWindow, {
name: `${epgPortalName} Offset`,
username: epgCredentials.username,
password: epgCredentials.password,
});
await waitForXtreamWorkspaceReady(app.mainWindow);
await openWorkspaceSection(app.mainWindow, 'Live TV');
await clickCategoryByNameExact(app.mainWindow, fixture.categoryName);
const channelRow = channelItemByTitle(
app.mainWindow,
fixture.stream.name ?? ''
).first();
await expect(channelRow).toBeVisible({ timeout: 20000 });
// Sidebar preview: the shifted programme, with shifted times.
await expect
.poll(async () =>
(
(await channelRow.locator('.epg-title').textContent()) ??
''
).trim()
)
.toBe(expectedProgram.title);
await expect
.poll(async () =>
(await channelRow.locator('.epg-time').allInnerTexts()).map(
(value) => value.trim()
)
)
.toEqual([
formatTimeInZone(
expectedProgram.startTimestamp + offsetMinutes * 60,
'UTC'
),
formatTimeInZone(
expectedProgram.stopTimestamp + offsetMinutes * 60,
'UTC'
),
]);
// Timeline: the same programme is the highlighted "now" block.
await channelRow.click();
await expect(app.mainWindow.locator('app-epg-timeline')).toBeVisible({
timeout: 20000,
});
await expect(
app.mainWindow
.locator(
'app-epg-timeline .epg-timeline__block.is-now .epg-timeline__block-title'
)
.first()
).toHaveText(expectedProgram.title);
} finally {
await closeElectronApp(app);
}
});
test('@epg @xtream @electron renders the vertical list view when the setting is "list"', async ({
dataDir,
request,