MaintenanceScheduleHelper { @SuppressWarnings("squid:S1166") public static Optional<ZonedDateTime> getNextMaintenanceWindow(final String cronSchedule, final String duration, final String timezone) { try { final ExecutionTime scheduleExecutor = ExecutionTime.forCron(getCronFromExpression(cronSchedule)); final ZonedDateTime now = ZonedDateTime.now(ZoneOffset.of(timezone)); final ZonedDateTime after = now.minus(convertToISODuration(duration)); final ZonedDateTime next = scheduleExecutor.nextExecution(after); return Optional.of(next); } catch (final RuntimeException ignored) { return Optional.empty(); } } private  MaintenanceScheduleHelper(); @SuppressWarnings("squid:S1166") static Optional<ZonedDateTime> getNextMaintenanceWindow(final String cronSchedule, final String duration,
            final String timezone); static Cron getCronFromExpression(final String cronSchedule); static void validateMaintenanceSchedule(final String cronSchedule, final String duration,
            final String timezone); static Duration convertToISODuration(final String timeInterval); static void validateDuration(final String duration); static void validateCronSchedule(final String cronSchedule);  }
@Test @Description("Verifies that there is a maintenance window available for correct schedule, duration and timezone") public void getNextMaintenanceWindowValid() { final ZonedDateTime currentTime = ZonedDateTime.now(); final String cronSchedule = String.format("0 %d %d %d %d ? %d", currentTime.getMinute(), currentTime.getHour(), currentTime.getDayOfMonth(), currentTime.getMonthValue(), currentTime.getYear()); final String duration = "00:10"; final String timezone = ZonedDateTime.now().getOffset().getId().replace("Z", "+00:00"); assertThat(MaintenanceScheduleHelper.getNextMaintenanceWindow(cronSchedule, duration, timezone)).isPresent(); }