feat: NbpService#getFetchDate implementation
This commit is contained in:
parent
310a4c4087
commit
497574b618
1 changed files with 8 additions and 1 deletions
|
@ -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) {
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue