Skip to content

Commit

Permalink
Isoformat conversion patch
Browse files Browse the repository at this point in the history
Datetime on windows fails when converting from iso format.
Work-around the issue by manual parsing
  • Loading branch information
thalman committed Feb 9, 2024
1 parent 69f69ef commit 02119c2
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/neknihy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,32 @@ def refreshRents(self):
self.saveBooks()
self.updateStatus()

def dateFromString(self, date):
try:
return datetime.fromisoformat(date)
except Exception:
pass
try:
y = None
m = None
d = None
if re.match(r'^\d{4}-\d{2}-\d{2}', date):
y = date[0:4]
m = date[5:7]
d = date[8:10]
if re.match(r'^\d{6}', date):
y = date[0:4]
m = date[4:6]
d = date[6:8]
if y is not None:
return datetime(int(y), int(m), int(d), tzinfo=timezone.utc)
except Exception:
pass
return datetime.now(timezone.utc)

def bookExpired(self, book):
if "end_time" in book:
time = datetime.fromisoformat(book["end_time"])
time = self.dateFromString(book["end_time"])
if time < datetime.now(timezone.utc):
return True
return False
Expand Down

0 comments on commit 02119c2

Please sign in to comment.