feat: NbpService#getFetchDate implementation

This commit is contained in:
Piotr Dec 2024-05-23 21:10:18 +02:00
parent 310a4c4087
commit 497574b618
Signed by: stawros
GPG key ID: F89F27AD8F881A91

View file

@ -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) {
}