feat: use datetime to compute time_left and time_elapsed
This commit is contained in:
parent
e4078504ba
commit
d79d4e371e
1 changed files with 10 additions and 9 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import time
|
from datetime import datetime, timedelta
|
||||||
from sqlite3 import Row
|
from sqlite3 import Row
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
|
@ -38,16 +38,17 @@ class Charges(BaseModel):
|
||||||
def from_row(cls, row: Row) -> "Charges":
|
def from_row(cls, row: Row) -> "Charges":
|
||||||
return cls(**dict(row))
|
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
|
@property
|
||||||
def time_elapsed(self):
|
def time_elapsed(self):
|
||||||
# todo:
|
return self.time_left < 0
|
||||||
# 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
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def paid(self):
|
def paid(self):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue