From e492c7ae0f0c5cd5f0d7db410189619f6aba19eb Mon Sep 17 00:00:00 2001 From: Kyle Corry Date: Sat, 20 Jan 2024 09:17:14 -0500 Subject: [PATCH] Fix tides being returned for more than one day --- .../kylecorry/trail_sense/tools/tides/domain/TideService.kt | 3 ++- .../trail_sense/tools/tides/domain/TideServiceTest.kt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/tides/domain/TideService.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/tides/domain/TideService.kt index bdac21ec7..6a764c928 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/tides/domain/TideService.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/tides/domain/TideService.kt @@ -26,7 +26,8 @@ class TideService : ITideService { val end = date.plusDays(1).atStartOfDay().toZonedDateTime(zone) val waterLevelCalculator = TideTableWaterLevelCalculator(table) val extremaFinder = GoldenRatioExtremaFinder(30.0, 1.0) - return ocean.getTides(waterLevelCalculator, start, end, extremaFinder) + val tides = ocean.getTides(waterLevelCalculator, start, end, extremaFinder) + return tides.filter { it.time.toLocalDate() == date } } private fun LocalDateTime.toZonedDateTime(zone: ZoneId): ZonedDateTime { diff --git a/app/src/test/java/com/kylecorry/trail_sense/tools/tides/domain/TideServiceTest.kt b/app/src/test/java/com/kylecorry/trail_sense/tools/tides/domain/TideServiceTest.kt index 6dad3b94f..c4465b7c7 100644 --- a/app/src/test/java/com/kylecorry/trail_sense/tools/tides/domain/TideServiceTest.kt +++ b/app/src/test/java/com/kylecorry/trail_sense/tools/tides/domain/TideServiceTest.kt @@ -386,7 +386,7 @@ internal class TideServiceTest { if (exact) 0.0001f else 1.5f ) val delta = Duration.between(actual.time, expected.time).seconds / 60f - Assertions.assertEquals(0f, delta, if (exact) 0f else 90f) + Assertions.assertEquals(0f, delta, if (exact) 1f else 90f) } }