From 0f2f1172ef24aef0c1b0245c83d066b0e8368238 Mon Sep 17 00:00:00 2001 From: Nico Montanari Date: Tue, 14 Jul 2026 18:22:55 +0200 Subject: [PATCH] fix: update Estofex report time parsing to handle UTC format correctly --- src/utilities/estofex.ts | 7 +++++-- tests/utilities/estofex.ts | 26 ++++++++++++++------------ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/utilities/estofex.ts b/src/utilities/estofex.ts index cc21586..27ee862 100644 --- a/src/utilities/estofex.ts +++ b/src/utilities/estofex.ts @@ -10,8 +10,11 @@ export const checkEstofexReport = (report: EstofexReport): boolean => { return false } - const startTime = customMoment(parseInt(report.forecast.start_time['@_value'], 10)) - const expiryTime = customMoment(parseInt(report.forecast.expiry_time['@_value'], 10)) + // Estofex emits start/expiry as a UTC 'YYYYMMDDHH' string (e.g. "2026071506"), NOT an epoch. + // Parsing it as a number and feeding moment() read it as ms-since-epoch (Jan 1970), so the + // window never straddled "tomorrow" and the report was always skipped. + const startTime = customMoment.utc(report.forecast.start_time['@_value'], 'YYYYMMDDHH') + const expiryTime = customMoment.utc(report.forecast.expiry_time['@_value'], 'YYYYMMDDHH') const tomorrow = customMoment().add(1, 'day') diff --git a/tests/utilities/estofex.ts b/tests/utilities/estofex.ts index 70dc5e4..f6a7cae 100644 --- a/tests/utilities/estofex.ts +++ b/tests/utilities/estofex.ts @@ -8,9 +8,8 @@ describe('tests/utilities/estofex.ts', () => { describe('checkEstofexReport', () => { let clock: SinonFakeTimers - const baseTimestamp = Date.UTC(2024, 4, 10, 0, 0, 0) // 10 maggio 2024 00:00:00 UTC - const oneDayMs = 24 * 60 * 60 * 1000 - const twelveHoursMs = 12 * 60 * 60 * 1000 + // Estofex emits start/expiry as a UTC 'YYYYMMDDHH' string. "Now" is 10 May 2024 00:00 UTC. + const baseTimestamp = Date.UTC(2024, 4, 10, 0, 0, 0) beforeEach(() => { clock = sinon.useFakeTimers(baseTimestamp) @@ -30,7 +29,7 @@ describe('tests/utilities/estofex.ts', () => { const withoutStart: EstofexReport = { forecast: { expiry_time: { - '@_value': String(baseTimestamp + oneDayMs), + '@_value': '2024051100', }, }, } @@ -38,7 +37,7 @@ describe('tests/utilities/estofex.ts', () => { const withoutExpiry: EstofexReport = { forecast: { start_time: { - '@_value': String(baseTimestamp), + '@_value': '2024051000', }, }, } @@ -52,7 +51,7 @@ describe('tests/utilities/estofex.ts', () => { forecast: { start_time: {}, expiry_time: { - '@_value': String(baseTimestamp + oneDayMs), + '@_value': '2024051100', }, }, } @@ -61,13 +60,14 @@ describe('tests/utilities/estofex.ts', () => { }) it('returns true when the report covers the current day plus one', () => { + // start 10 May 12:00, expiry 11 May 12:00 UTC — straddles "tomorrow" (11 May 00:00). const report: EstofexReport = { forecast: { start_time: { - '@_value': String(baseTimestamp + twelveHoursMs), + '@_value': '2024051012', }, expiry_time: { - '@_value': String(baseTimestamp + oneDayMs + twelveHoursMs), + '@_value': '2024051112', }, }, } @@ -76,13 +76,14 @@ describe('tests/utilities/estofex.ts', () => { }) it('returns false when the report starts after tomorrow', () => { + // start 11 May 12:00 — after tomorrow (11 May 00:00). const report: EstofexReport = { forecast: { start_time: { - '@_value': String(baseTimestamp + oneDayMs + twelveHoursMs), + '@_value': '2024051112', }, expiry_time: { - '@_value': String(baseTimestamp + 3 * oneDayMs), + '@_value': '2024051300', }, }, } @@ -91,13 +92,14 @@ describe('tests/utilities/estofex.ts', () => { }) it('returns false when the report ends before tomorrow', () => { + // expiry 10 May 12:00 — before tomorrow (11 May 00:00). const report: EstofexReport = { forecast: { start_time: { - '@_value': String(baseTimestamp), + '@_value': '2024051000', }, expiry_time: { - '@_value': String(baseTimestamp + twelveHoursMs), + '@_value': '2024051012', }, }, }