Repository: borgbackup/borg

Issue:
Borg2: ValueError on date-based matching
## Have you checked borgbackup docs, FAQ, and open GitHub issues?

Yes

## Is this a BUG / ISSUE report or a QUESTION?

BUG

## System information. For client/server mode post info for both machines.

#### Your borg version (borg -V).
borg 2.0.0b5

#### Operating system (distribution) and version.
Tested on WSL2 (Debian 11) and Kali 

#### How much data is handled by borg?
2 archives adding one new file each (total text 2 files)

#### Full borg commandline that lead to the problem (leave away excludes and passwords)
```
borg rlist --older 1d --repo XXX
```


## Describe the problem you're observing.

I'm getting ValueError on running `borg rlist --older 1d` on a new repo which does not have archives older than a day.

Introduced in #7272 

https://github.com/borgbackup/borg/pull/7272/files#diff-56ce27fae07c0d4ca00050b58f86125f91d88cb4016e38f7c2d5890de9a4e0f7R39-R40

archives_list is empty so min raises ValueError. Perhaps add a check?

```
Traceback (most recent call last):
...
  File "/home/xxx/Projects/borg/env/lib/python3.9/site-packages/borg/manifest.py", line 141, in list
    archives = filter_archives_by_date(archives, oldest=oldest, newest=newest, newer=newer, older=older)
  File "/home/xxx/Projects/borg/env/lib/python3.9/site-packages/borg/manifest.py", line 50, in filter_archives_by_date
    earliest_ts, latest_ts = get_first_and_last_archive_ts(archives)
  File "/home/xxx/Projects/borg/env/lib/python3.9/site-packages/borg/manifest.py", line 41, in get_first_and_last_archive_ts
    return min(timestamps), max(timestamps)
ValueError: min() arg is an empty sequence
```

#### Can you reproduce the problem? If so, describe how. If not, describe troubleshooting steps you took before opening the issue.
create a new repo with two archives (both adding one new file). Now run the rlist command with `--older 1d`



Discussion:
@jetchirag thanks for reporting this!

@Michael-Girma can you have a look?

Resolving patch:
diff --git a/src/borg/manifest.py b/src/borg/manifest.py
--- a/src/borg/manifest.py
+++ b/src/borg/manifest.py
@@ -39,6 +39,9 @@ def get_first_and_last_archive_ts(archives_list):
         timestamps = [x.ts for x in archives_list]
         return min(timestamps), max(timestamps)
 
+    if not archives:
+        return archives
+
     now = archive_ts_now()
     earliest_ts, latest_ts = get_first_and_last_archive_ts(archives)
 
@@ -46,6 +49,9 @@ def get_first_and_last_archive_ts(archives_list):
     from_ts = calculate_relative_offset(newer, now, earlier=True) if newer is not None else earliest_ts
     archives = [x for x in archives if from_ts <= x.ts <= until_ts]
 
+    if not archives:
+        return archives
+
     earliest_ts, latest_ts = get_first_and_last_archive_ts(archives)
     if oldest:
         until_ts = calculate_relative_offset(oldest, earliest_ts, earlier=False)
@@ -136,7 +142,7 @@ def list(
         regex = re.compile(regex + match_end)
         archives = [x for x in archives if regex.match(x.name) is not None]
 
-        if any([oldest, newest, older, newer]) and len(archives) > 0:
+        if any([oldest, newest, older, newer]):
             archives = filter_archives_by_date(archives, oldest=oldest, newest=newest, newer=newer, older=older)
         if not consider_checkpoints:
             archives = [x for x in archives if ".checkpoint" not in x.name]
diff --git a/src/borg/testsuite/archiver/check_cmd.py b/src/borg/testsuite/archiver/check_cmd.py
--- a/src/borg/testsuite/archiver/check_cmd.py
+++ b/src/borg/testsuite/archiver/check_cmd.py
@@ -92,6 +92,13 @@ def test_date_matching(self):
         self.assert_in("archive2", output)
         self.assert_not_in("archive3", output)
 
+        # check for output when timespan older than earliest archive is given. Issue #1711
+        output = self.cmd(
+            f"--repo={self.repository_location}", "check", "-v", "--archives-only", "--older=9999m", exit_code=0
+        )
+        for archive in ("archive1", "archive2", "archive3"):
+            self.assert_not_in(archive, output)
+
     def test_missing_file_chunk(self):
         archive, repository = self.open_archive("archive1")
         with repository:


Test patch: