I need to implement function
int secondsTillNextSaturday(LocalDateTime start);
Which does pretty same as it says, calculates number of seconds till next Saturday relatively to start time(if start is already Saturday, then it should return number of seconds till next Saturday after it).
For example for 27.04.2017 00:00:00 (Thursday) it should return 2 * 24 * 60 * 60.
It could be done easily using java 8 time api:
public long secondsTillNextSaturday(LocalDateTime start) {
LocalDate nextSaturday = start.toLocalDate().with(TemporalAdjusters.next(DayOfWeek.SATURDAY));
return ChronoUnit.SECONDS.between(start, nextSaturday.atStartOfDay());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With