Home > database >  How do I restrict a method so that it will only run on certain days if called?
How do I restrict a method so that it will only run on certain days if called?

Time:08-03

I want to restrict a method to only be executable on weekdays. Is there a spring annotation that would allow for this? Im trying to avoid writing a method that just checks the day of the week and exits.

CodePudding user response:

I don't think there's any comment to check the day of the week in the spring.

You may need to use the following methods:

public void checkDate() {
    
    LocalDate localDate = LocalDate.now();
    
    DayOfWeek dayOfWeek = localDate.getDayOfWeek();
    
    if(dayOfWeek == DayOfWeek.SATURDAY || dayOfWeek == DayOfWeek.SUNDAY) {
        // ...do something
    }
    
}
  • Related