diff --git a/src/repositories/shuttle/eta/InMemorySelfUpdatingETARepository.ts b/src/repositories/shuttle/eta/InMemorySelfUpdatingETARepository.ts index 917e6bc..89212ab 100644 --- a/src/repositories/shuttle/eta/InMemorySelfUpdatingETARepository.ts +++ b/src/repositories/shuttle/eta/InMemorySelfUpdatingETARepository.ts @@ -110,25 +110,26 @@ export class InMemorySelfUpdatingETARepository extends BaseInMemoryETARepository const oneWeekAgo = new Date(referenceCurrentTime.getTime() - (60 * 60 * 24 * 7 * 1000)); const oneDayAgo = new Date(referenceCurrentTime.getTime() - (60 * 60 * 24 * 1000)); - const oneHourAgo = new Date(referenceCurrentTime.getTime() - (60 * 60 * 1000)); + const twoHoursAgo = new Date(referenceCurrentTime.getTime() - (60 * 60 * 1000)); + const twoHoursInMs = 120 * 60 * 1000; const travelTimeSeconds = await this.getAverageTravelTimeSecondsWithFallbacks({ routeId: shuttle.routeId, fromStopId: currentStop.stopId, toStopId: nextStop.stopId, }, [ { - from: oneWeekAgo, - to: new Date(oneWeekAgo.getTime() + (60 * 60 * 1000)) - }, - { - from: oneDayAgo, - to: new Date(oneDayAgo.getTime() + (60 * 60 * 1000)) - }, - { - from: oneHourAgo, + from: twoHoursAgo, to: new Date(), - } + }, + { + from: new Date(oneDayAgo.getTime() - (twoHoursInMs)), + to: oneDayAgo, + }, + { + from: new Date(oneWeekAgo.getTime() - (twoHoursInMs)), + to: oneWeekAgo, + }, ]); if (travelTimeSeconds == undefined) return; diff --git a/src/repositories/shuttle/eta/RedisSelfUpdatingETARepository.ts b/src/repositories/shuttle/eta/RedisSelfUpdatingETARepository.ts index 60e07b4..76e723b 100644 --- a/src/repositories/shuttle/eta/RedisSelfUpdatingETARepository.ts +++ b/src/repositories/shuttle/eta/RedisSelfUpdatingETARepository.ts @@ -133,23 +133,24 @@ export class RedisSelfUpdatingETARepository extends BaseRedisETARepository imple const oneDayAgo = new Date(referenceCurrentTime.getTime() - (60 * 60 * 24 * 1000)); const twoHoursAgo = new Date(referenceCurrentTime.getTime() - (120 * 60 * 1000)); + const twoHoursInMs = 120 * 60 * 1000; const travelTimeSeconds = await this.getAverageTravelTimeSecondsWithFallbacks({ routeId: shuttle.routeId, fromStopId: currentStop.stopId, toStopId: nextStop.stopId, }, [ - { - from: oneWeekAgo, - to: new Date(oneWeekAgo.getTime() + (60 * 60 * 1000)) - }, - { - from: oneDayAgo, - to: new Date(oneDayAgo.getTime() + (60 * 60 * 1000)) - }, { from: twoHoursAgo, to: new Date(), - } + }, + { + from: new Date(oneDayAgo.getTime() - (twoHoursInMs)), + to: oneDayAgo, + }, + { + from: new Date(oneWeekAgo.getTime() - (twoHoursInMs)), + to: oneWeekAgo, + }, ]); if (travelTimeSeconds == undefined) return; diff --git a/src/repositories/shuttle/eta/__tests__/SelfUpdatingETARepositorySharedTests.test.ts b/src/repositories/shuttle/eta/__tests__/SelfUpdatingETARepositorySharedTests.test.ts index f490b0f..b260e3e 100644 --- a/src/repositories/shuttle/eta/__tests__/SelfUpdatingETARepositorySharedTests.test.ts +++ b/src/repositories/shuttle/eta/__tests__/SelfUpdatingETARepositorySharedTests.test.ts @@ -121,9 +121,9 @@ describe.each(repositoryImplementations)('$name', (holder) => { const { route, systemId, stop1, stop2, stop3 } = await setupRouteAndOrderedStops(); // Populating travel time data - const firstStopArrivalTime = new Date(2025, 0, 1, 12, 0, 0); - const secondStopArrivalTime = new Date(2025, 0, 1, 12, 15, 0); - const thirdStopArrivalTime = new Date(2025, 0, 1, 12, 20, 0); + const firstStopArrivalTime = new Date(2025, 0, 1, 11, 0, 0); + const secondStopArrivalTime = new Date(2025, 0, 1, 11, 15, 0); + const thirdStopArrivalTime = new Date(2025, 0, 1, 11, 20, 0); repository.setReferenceTime(currentTime); repository.startListeningForUpdates(); @@ -185,8 +185,8 @@ describe.each(repositoryImplementations)('$name', (holder) => { ); }, 60000); - test("uses previous hour fallback calculation when no data available from one day ago", async () => { - const shuttleSecondArrivalTimeAtFirstStop = new Date(2025, 0, 1, 13, 5, 0); + test("uses previous two-hour fallback calculation when no data available from one day ago", async () => { + const shuttleSecondArrivalTimeAtFirstStop = new Date(2025, 0, 1, 12, 5, 0); const currentTime = new Date(shuttleSecondArrivalTimeAtFirstStop.getTime() + 7 * 60 * 1000); await assertEtaIsValidGivenCurrentTimeAndSecondArrivalTime( currentTime, shuttleSecondArrivalTimeAtFirstStop