Skip to content

Commit 298b639

Browse files
fix next schedule backup selection
1 parent 1e8e6f8 commit 298b639

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

DriveBackup/src/main/java/ratismal/drivebackup/UploadThread.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
import java.util.Iterator;
5454
import java.util.List;
5555
import java.util.Map;
56+
import java.util.NoSuchElementException;
57+
import java.util.Optional;
5658
import java.util.TreeMap;
5759

5860
import static ratismal.drivebackup.config.Localization.intl;
@@ -582,14 +584,11 @@ public static String getBackupStatus() {
582584
public static String getNextAutoBackup() {
583585
Config config = ConfigParser.getConfig();
584586
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);
593592
DateTimeFormatter backupDateFormatter = DateTimeFormatter.ofPattern(intl("next-schedule-backup-format"), config.advanced.dateLanguage);
594593
return intl("next-schedule-backup").replaceAll("%DATE", nextBackupDate.format(backupDateFormatter));
595594
} else if (config.backupStorage.delay != -1) {

0 commit comments

Comments
 (0)