Skip to content

Commit

Permalink
fix: Makes time comparison logic neater
Browse files Browse the repository at this point in the history
  • Loading branch information
ntlhui committed Sep 23, 2024
1 parent d302d46 commit bd54905
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions e4e_data_management/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,19 @@ def add_files_cmd(self,
resolved_paths: List[Path] = []
for path in paths:
resolved_paths.extend(Path(file) for file in glob(path))
if start:
if start.tzinfo is None:
start = start.replace(tzinfo=local_tz)
resolved_paths = [path
for path in resolved_paths
if dt.datetime.fromtimestamp(path.stat().st_mtime, local_tz) >= start]
if end:
if end.tzinfo is None:
end = end.replace(tzinfo=local_tz)
resolved_paths = [path
for path in resolved_paths
if dt.datetime.fromtimestamp(path.stat().st_mtime, local_tz) <= end]
if not start:
start = dt.datetime.min
if not end:
end = dt.datetime.max
if start.tzinfo is None:
start = start.replace(tzinfo=local_tz)
if end.tzinfo is None:
end = end.replace(tzinfo=local_tz)
if end < start:
raise RuntimeError('end before start')
resolved_paths = [path
for path in resolved_paths
if start <= dt.datetime.fromtimestamp(path.stat().st_mtime, local_tz) <= end]
self.app.add(paths=resolved_paths, readme=readme, destination=destination)

def status_cmd(self):
Expand Down

0 comments on commit bd54905

Please sign in to comment.