|
53 | 53 | import java.util.Iterator; |
54 | 54 | import java.util.List; |
55 | 55 | import java.util.Map; |
| 56 | +import java.util.NoSuchElementException; |
| 57 | +import java.util.Optional; |
56 | 58 | import java.util.TreeMap; |
57 | 59 |
|
58 | 60 | import static ratismal.drivebackup.config.Localization.intl; |
@@ -582,14 +584,11 @@ public static String getBackupStatus() { |
582 | 584 | public static String getNextAutoBackup() { |
583 | 585 | Config config = ConfigParser.getConfig(); |
584 | 586 | if (config.backupScheduling.enabled) { |
585 | | - long now = ZonedDateTime.now(config.advanced.dateTimezone).toEpochSecond(); |
586 | | - ZonedDateTime nextBackupDate = Collections.min(Scheduler.getBackupDatesList(), new Comparator<ZonedDateTime>() { |
587 | | - public int compare(ZonedDateTime d1, ZonedDateTime d2) { |
588 | | - long diff1 = Math.abs(d1.toEpochSecond() - now); |
589 | | - long diff2 = Math.abs(d2.toEpochSecond() - now); |
590 | | - return Long.compare(diff1, diff2); |
591 | | - } |
592 | | - }); |
| 587 | + ZonedDateTime now = ZonedDateTime.now(config.advanced.dateTimezone); |
| 588 | + ZonedDateTime nextBackupDate = Scheduler.getBackupDatesList().stream() |
| 589 | + .filter(zdt -> zdt.isAfter(now)) |
| 590 | + .min(Comparator.naturalOrder()) |
| 591 | + .orElseThrow(NoSuchElementException::new); |
593 | 592 | DateTimeFormatter backupDateFormatter = DateTimeFormatter.ofPattern(intl("next-schedule-backup-format"), config.advanced.dateLanguage); |
594 | 593 | return intl("next-schedule-backup").replaceAll("%DATE", nextBackupDate.format(backupDateFormatter)); |
595 | 594 | } else if (config.backupStorage.delay != -1) { |
|
0 commit comments