mirror of
https://github.com/lnbits/lnbits.git
synced 2025-10-11 04:52:34 +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 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):
|
||||||
|
Reference in New Issue
Block a user