mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-27 12:26:19 +02:00
feat: use datetime
to compute time_left
and time_elapsed
This commit is contained in:
@@ -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):
|
||||
|
Reference in New Issue
Block a user