mirror of
https://gitea.publichub.eu/oscar.krause/fastapi-dls.git
synced 2024-12-29 00:48:49 +00:00
fixed timezone handling
This commit is contained in:
parent
f199800040
commit
f35a4c6145
@ -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),
|
||||
})
|
||||
|
||||
|
||||
|
10
app/orm.py
10
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))
|
||||
|
@ -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 = `
|
||||
<td><code>${o.lease_ref}</code></td>
|
||||
<td>${o.lease_created}</td>
|
||||
<td>${o.lease_updated}</td>
|
||||
<td>${o.lease_expires}</td>
|
||||
<td>${new Date(o.lease_created).toLocaleDateString('system', dtc)}</td>
|
||||
<td>${new Date(o.lease_updated).toLocaleDateString('system', dtc)}</td>
|
||||
<td>${new Date(o.lease_expires).toLocaleDateString('system', dtc)}</td>
|
||||
<td><code>${o.origin_ref}</code></td>`
|
||||
tbody.appendChild(row);
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user