From 497574b618e6b4a526107bfcbfa71acf825ea896 Mon Sep 17 00:00:00 2001 From: Piotr Dec Date: Thu, 23 May 2024 21:10:18 +0200 Subject: [PATCH] feat: NbpService#getFetchDate implementation --- src/main/java/eu/ztsh/wymiana/service/NbpService.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/ztsh/wymiana/service/NbpService.java b/src/main/java/eu/ztsh/wymiana/service/NbpService.java index 159ca0e..1871f54 100644 --- a/src/main/java/eu/ztsh/wymiana/service/NbpService.java +++ b/src/main/java/eu/ztsh/wymiana/service/NbpService.java @@ -6,7 +6,9 @@ import org.assertj.core.util.VisibleForTesting; import org.springframework.stereotype.Service; import java.time.Clock; +import java.time.DayOfWeek; import java.time.LocalDate; +import java.time.temporal.TemporalAdjusters; /** * NBP exchange rates service @@ -34,7 +36,8 @@ public class NbpService { */ @VisibleForTesting LocalDate getFetchDate() { - throw new UnsupportedOperationException("Not implemented yet"); + var today = LocalDate.now(clock); + return isWeekend(today) ? today.with(TemporalAdjusters.previous(DayOfWeek.FRIDAY)) : today; } @VisibleForTesting @@ -42,6 +45,10 @@ public class NbpService { throw new UnsupportedOperationException("Not implemented yet"); } + private static boolean isWeekend(LocalDate today) { + return today.getDayOfWeek() == DayOfWeek.SATURDAY + || today.getDayOfWeek() == DayOfWeek.SUNDAY; + } private record RatesCache(LocalDate date, double buy, double sell) { }