Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/utilities/estofex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
26 changes: 14 additions & 12 deletions tests/utilities/estofex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -30,15 +29,15 @@ describe('tests/utilities/estofex.ts', () => {
const withoutStart: EstofexReport = {
forecast: {
expiry_time: {
'@_value': String(baseTimestamp + oneDayMs),
'@_value': '2024051100',
},
},
}

const withoutExpiry: EstofexReport = {
forecast: {
start_time: {
'@_value': String(baseTimestamp),
'@_value': '2024051000',
},
},
}
Expand All @@ -52,7 +51,7 @@ describe('tests/utilities/estofex.ts', () => {
forecast: {
start_time: {},
expiry_time: {
'@_value': String(baseTimestamp + oneDayMs),
'@_value': '2024051100',
},
},
}
Expand All @@ -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',
},
},
}
Expand All @@ -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',
},
},
}
Expand All @@ -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',
},
},
}
Expand Down
Loading