diff --git a/app/main.py b/app/main.py index beb3aff..08fa0f1 100644 --- a/app/main.py +++ b/app/main.py @@ -27,6 +27,8 @@ from orm import Origin, Lease, init as db_init, migrate logger = logging.getLogger() load_dotenv('../version.env') +TZ = datetime.now().astimezone().tzinfo + VERSION, COMMIT, DEBUG = env('VERSION', 'unknown'), env('COMMIT', 'unknown'), bool(env('DEBUG', False)) config = dict(openapi_url='/-/openapi.json', docs_url='/-/docs', redoc_url='/-/redoc') @@ -101,6 +103,7 @@ async def _config(): 'LEASE_EXPIRE_DELTA': str(LEASE_EXPIRE_DELTA), 'LEASE_RENEWAL_PERIOD': str(LEASE_RENEWAL_PERIOD), 'CORS_ORIGINS': str(CORS_ORIGINS), + 'TZ': str(TZ), }) diff --git a/app/orm.py b/app/orm.py index aadc0ef..063c12d 100644 --- a/app/orm.py +++ b/app/orm.py @@ -1,4 +1,4 @@ -import datetime +from datetime import datetime, timezone from sqlalchemy import Column, VARCHAR, CHAR, ForeignKey, DATETIME, update, and_, inspect from sqlalchemy.ext.declarative import declarative_base @@ -86,9 +86,9 @@ class Lease(Base): 'lease_ref': self.lease_ref, 'origin_ref': self.origin_ref, # 'scope_ref': self.scope_ref, - 'lease_created': self.lease_created.isoformat(), - 'lease_expires': self.lease_expires.isoformat(), - 'lease_updated': self.lease_updated.isoformat(), + 'lease_created': self.lease_created.replace(tzinfo=timezone.utc).isoformat(), + 'lease_expires': self.lease_expires.replace(tzinfo=timezone.utc).isoformat(), + 'lease_updated': self.lease_updated.replace(tzinfo=timezone.utc).isoformat(), } @staticmethod @@ -133,7 +133,7 @@ class Lease(Base): return entity @staticmethod - def renew(engine: Engine, lease: "Lease", lease_expires: datetime.datetime, lease_updated: datetime.datetime): + def renew(engine: Engine, lease: "Lease", lease_expires: datetime, lease_updated: datetime): session = sessionmaker(bind=engine)() x = dict(lease_expires=lease_expires, lease_updated=lease_updated) session.execute(update(Lease).where(and_(Lease.origin_ref == lease.origin_ref, Lease.lease_ref == lease.lease_ref)).values(**x)) diff --git a/app/static/assets/js/helper.js b/app/static/assets/js/helper.js index 90f3e8d..d1fd912 100644 --- a/app/static/assets/js/helper.js +++ b/app/static/assets/js/helper.js @@ -49,6 +49,17 @@ async function fetchOriginsWithLeases(element) { } async function fetchLeases(element) { + // datetime config + const dtc = { + year: "numeric", + month: "2-digit", + day: "2-digit", + hour: "2-digit", + minute: "2-digit", + second: "2-digit", + timeZoneName: "short" + } + let xhr = new XMLHttpRequest(); xhr.open("GET", '/-/leases?origin=true', true); xhr.onreadystatechange = function () { @@ -74,9 +85,9 @@ async function fetchLeases(element) { let row = document.createElement('tr'); row.innerHTML = `
${o.lease_ref}
${o.origin_ref}