List of usage examples for java.time LocalDateTime getHour
public int getHour()
From source file:org.codice.ddf.admin.insecure.defaults.service.DefaultUsersDeletionScheduler.java
private String cronCalculator(Instant firstInstall) { Instant threeDayTimestamp = firstInstall.plus(Duration.ofDays(3).minus(Duration.ofMinutes(30))); LocalDateTime localDateTime = LocalDateTime.ofInstant(threeDayTimestamp, ZoneId.systemDefault()); return String.format("%d+%d+%d+%d+%d+?+%d", localDateTime.getSecond(), localDateTime.getMinute(), localDateTime.getHour(), localDateTime.getDayOfMonth(), localDateTime.getMonthValue(), localDateTime.getYear());//from w w w . j a v a 2 s. c o m }
From source file:org.eclipse.smarthome.core.scheduler.CronHelper.java
/** * Returns CRON expression from the provided {@link LocalDateTime} instance * * @param localDateTime the {@link LocalDateTime} instance * @return the CRON expression/*from www . j ava2s . com*/ * @throws NullPointerException * if {@code localDateTime} is null */ public static String createCronFromTemporal(LocalDateTime localDateTime) { requireNonNull(localDateTime, "Temporal instance cannot be null"); int minute = localDateTime.getMinute(); int hour = localDateTime.getHour(); int day = localDateTime.getDayOfMonth(); int month = localDateTime.getMonth().getValue(); int year = localDateTime.getYear(); StringBuilder builder = new StringBuilder(); builder.append(SECONDS).append(SPACE).append(minute).append(SPACE).append(hour).append(SPACE).append(day) .append(SPACE).append(month).append(SPACE).append(DAYS_OF_WEEK).append(SPACE).append(year); return builder.toString(); }
From source file:org.eclipse.smarthome.core.scheduler.CronHelper.java
/** * Returns CRON expression that denotes the repetition every provided * seconds//from w w w.j a v a 2 s .c o m * * @param totalSecs the seconds (cannot be zero or negative or more than 86400) * @return the CRON expression * @throws IllegalArgumentException * if {@code totalSecs} is zero or negative or more than 86400 */ public static String createCronForRepeatEverySeconds(int totalSecs) { if (totalSecs < 0 && totalSecs <= 86400) { throw new IllegalArgumentException("Seconds cannot be zero or negative or more than 86400"); } StringBuilder builder = new StringBuilder(); if (totalSecs < 60) { builder.append(ANY).append(EACH).append(totalSecs).append(SPACE).append(ANY).append(SPACE).append(ANY) .append(SPACE).append(ANY).append(SPACE).append(ANY).append(SPACE).append(DAYS_OF_WEEK) .append(SPACE).append(ANY); return builder.toString(); } if (totalSecs >= 60 && totalSecs < 60 * 60) { int secs = totalSecs % 60; int mins = totalSecs / 60; builder.append(secs).append(SPACE).append(ANY).append(EACH).append(mins).append(SPACE).append(ANY) .append(SPACE).append(ANY).append(SPACE).append(ANY).append(SPACE).append(DAYS_OF_WEEK) .append(SPACE).append(ANY); return builder.toString(); } if (totalSecs >= 60 * 60 && totalSecs < 60 * 60 * 24) { int secs = totalSecs % 60; int mins = totalSecs % 3600 / 60; int hours = totalSecs / 3600; builder.append(secs).append(SPACE).append(mins).append(SPACE).append(ANY).append(EACH).append(hours) .append(SPACE).append(ANY).append(SPACE).append(ANY).append(SPACE).append(DAYS_OF_WEEK) .append(SPACE).append(ANY); return builder.toString(); } if (totalSecs == 60 * 60 * 24) { LocalDateTime now = LocalDateTime.now(); int minute = now.getMinute(); int hour = now.getHour(); builder.append("0").append(SPACE).append(minute).append(SPACE).append(hour).append(SPACE).append(ANY) .append(SPACE).append(ANY).append(SPACE).append(DAYS_OF_WEEK).append(SPACE).append(ANY); return builder.toString(); } return EMPTY; }