Fixed timezone being returned incorrectly
Happened if you've set TZ to non-UTC. Apparently astimezone and replace doesn't do the same thing even if tzinfo is None.
This commit is contained in:
@@ -13,7 +13,7 @@ from spoolman.math import length_from_weight
|
||||
def datetime_to_str(dt: datetime) -> str:
|
||||
"""Convert a datetime object to a string."""
|
||||
if dt.tzinfo is None:
|
||||
dt = dt.astimezone(tz=timezone.utc)
|
||||
dt = dt.replace(tzinfo=timezone.utc)
|
||||
return dt.isoformat().replace("+00:00", "Z")
|
||||
|
||||
|
||||
|
||||
@@ -230,8 +230,8 @@ async def use_weight(db: AsyncSession, spool_id: int, weight: float) -> models.S
|
||||
spool = await get_by_id(db, spool_id)
|
||||
|
||||
if spool.first_used is None:
|
||||
spool.first_used = datetime.utcnow()
|
||||
spool.last_used = datetime.utcnow()
|
||||
spool.first_used = datetime.utcnow().replace(microsecond=0)
|
||||
spool.last_used = datetime.utcnow().replace(microsecond=0)
|
||||
|
||||
await db.commit()
|
||||
await spool_changed(spool)
|
||||
@@ -275,8 +275,8 @@ async def use_length(db: AsyncSession, spool_id: int, length: float) -> models.S
|
||||
spool = await get_by_id(db, spool_id)
|
||||
|
||||
if spool.first_used is None:
|
||||
spool.first_used = datetime.utcnow()
|
||||
spool.last_used = datetime.utcnow()
|
||||
spool.first_used = datetime.utcnow().replace(microsecond=0)
|
||||
spool.last_used = datetime.utcnow().replace(microsecond=0)
|
||||
|
||||
await db.commit()
|
||||
await spool_changed(spool)
|
||||
|
||||
Reference in New Issue
Block a user