diff --git a/src/repositories/shuttle/eta/InMemorySelfUpdatingETARepository.ts b/src/repositories/shuttle/eta/InMemorySelfUpdatingETARepository.ts index 917e6bc..868178f 100644 --- a/src/repositories/shuttle/eta/InMemorySelfUpdatingETARepository.ts +++ b/src/repositories/shuttle/eta/InMemorySelfUpdatingETARepository.ts @@ -110,23 +110,24 @@ 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: new Date(oneWeekAgo.getTime() - (twoHoursInMs)), + to: oneWeekAgo, }, { - from: oneDayAgo, - to: new Date(oneDayAgo.getTime() + (60 * 60 * 1000)) + from: new Date(oneDayAgo.getTime() - (twoHoursInMs)), + to: oneDayAgo, }, { - from: oneHourAgo, + from: twoHoursAgo, to: new Date(), } ]); diff --git a/src/repositories/shuttle/eta/RedisSelfUpdatingETARepository.ts b/src/repositories/shuttle/eta/RedisSelfUpdatingETARepository.ts index 4f61368..0514ec2 100644 --- a/src/repositories/shuttle/eta/RedisSelfUpdatingETARepository.ts +++ b/src/repositories/shuttle/eta/RedisSelfUpdatingETARepository.ts @@ -133,19 +133,19 @@ 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 twoHoursMs = 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() + (twoHoursMs)) + from: new Date(oneWeekAgo.getTime() - (twoHoursInMs)), + to: oneWeekAgo, }, { - from: oneDayAgo, - to: new Date(oneDayAgo.getTime() + (twoHoursMs)) + from: new Date(oneDayAgo.getTime() - (twoHoursInMs)), + to: oneDayAgo, }, { from: twoHoursAgo, 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