All Downloads are FREE. Search and download functionalities are using the official Maven repository.

os.failsafe.executor.schedule.DailySchedule Maven / Gradle / Ivy

There is a newer version: 2.1.1
Show newest version
package os.failsafe.executor.schedule;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Optional;

public class DailySchedule implements Schedule {

    private final LocalTime dailyTime;

    public DailySchedule(LocalTime dailyTime) {
        this.dailyTime = dailyTime;
    }

    @Override
    public Optional nextExecutionTime(LocalDateTime currentTime) {
        LocalDate nextExecutionDate;

        if(dailyTime.isAfter(currentTime.toLocalTime())) {
            nextExecutionDate = currentTime.toLocalDate();
        } else {
            nextExecutionDate = currentTime.toLocalDate().plusDays(1);
        }

        return Optional.of(LocalDateTime.of(nextExecutionDate, dailyTime));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy