feat: use datetime to compute time_left and time_elapsed

This commit is contained in:
Vlad Stan
2022-07-11 15:03:48 +03:00
parent e4078504ba
commit d79d4e371e

View File

@@ -1,4 +1,4 @@
import time
from datetime import datetime, timedelta
from sqlite3 import Row
from typing import Optional
@@ -38,16 +38,17 @@ class Charges(BaseModel):
def from_row(cls, row: Row) -> "Charges":
return cls(**dict(row))
@property
def time_left(self):
now = datetime.utcnow().timestamp()
start = datetime.fromtimestamp(self.timestamp)
expiration = (start + timedelta(minutes=self.time)).timestamp()
return (expiration - now) / 60
@property
def time_elapsed(self):
# todo:
# now = datetime.utcnow().timestamp()
# start = datetime.utcfromtimestamp(self.timestamp)
# expiration = (start + timedelta(minutes=self.time)).timestamp()
if (self.timestamp + (self.time * 60)) >= time.time():
return False
else:
return True
return self.time_left < 0
@property
def paid(self):