fix: get_expires_in logic for token cache

This commit is contained in:
phot0n 2023-01-01 22:43:33 +05:30
parent 9d6f82725e
commit 52daef0dfd

View file

@ -52,11 +52,10 @@ class TokenCache(Document):
return self
def get_expires_in(self):
modified = frappe.utils.get_datetime(self.modified)
expiry_utc = modified.astimezone(pytz.utc) + timedelta(seconds=self.expires_in)
now_utc = datetime.utcnow().replace(tzinfo=pytz.utc)
expiry_time = frappe.utils.get_datetime(self.modified) + timedelta(seconds=self.expires_in)
expiry_local = expiry_time.replace(tzinfo=pytz.timezone(frappe.utils.get_time_zone()))
expiry_utc = expiry_local.astimezone(pytz.utc)
return (expiry_utc - now_utc).total_seconds()
return cint((expiry_utc - now_utc).total_seconds())
def is_expired(self):
return self.get_expires_in() < 0