Skip to content

Commit

Permalink
web-add: fix TypeError: can't compare offset-naive and offset-aware d…
Browse files Browse the repository at this point in the history
…atetimes
  • Loading branch information
chapmanjacobd committed Jan 24, 2025
1 parent 24c3dde commit 7932106
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion library/playback/torrents_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ def shorten(s, width):

trackers = []
for tracker, tracker_torrents in torrents_by_tracker.items():
tracker_torrents = [t for t in tracker_torrents if t.state not in ("stoppedDL",)]
if not args.stopped:
tracker_torrents = [t for t in tracker_torrents if t.state not in ("stoppedDL",)]
remaining = sum(t.amount_left for t in tracker_torrents)
trackers.append(
{
Expand Down
17 changes: 15 additions & 2 deletions library/utils/date_utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import datetime
from datetime import timezone as tz

import dateutil.parser

from library.utils import iterables, nums

def is_tz_aware(dt: datetime.datetime) -> bool:
return dt.tzinfo is not None and dt.tzinfo.utcoffset(dt) is not None

def super_parser(date_str):
def maybe_tz_now(maybe_tz_dt: datetime.datetime):
if is_tz_aware(maybe_tz_dt):
now = datetime.datetime.now(tz=tz.utc).astimezone()
else:
now = datetime.datetime.now()
return now

def super_parser(date_str, fallback=False):
parsing_strategies = [
{}, # default
{"dayfirst": True},
Expand All @@ -19,10 +29,13 @@ def super_parser(date_str):
except dateutil.parser.ParserError:
continue

if fallback:
return date_str


def specific_date(*dates):
valid_dates = [super_parser(s) for s in dates if s]
past_dates = [d for d in valid_dates if d and d < datetime.datetime.now()]
past_dates = [d for d in valid_dates if d and d < maybe_tz_now(d)]
if not past_dates:
return None

Expand Down

0 comments on commit 7932106

Please sign in to comment.