diff --git a/main.py b/main.py index 23b9fd5..138806b 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,6 @@ import re -import time +from calendar import timegm +from datetime import date from fastapi import Depends, FastAPI, Response from fastapi.staticfiles import StaticFiles @@ -46,7 +47,7 @@ async def list_items(db: Session = Depends(get_db)): @app.put("/api/items/{id}") async def put_item(id: str, item: Item, db: Session = Depends(get_db)): if item.last_updated is None: - item.last_updated = rough_timestamp() + item.last_updated = month_timestamp() if crud.put_item(db, id, item) == crud.PutItemResult.UPDATED: return Response(b"", status_code=204) return Response(b"", status_code=201) @@ -57,10 +58,9 @@ async def delete_item(id: str, db: Session = Depends(get_db)): crud.delete_item(db, id) -def rough_timestamp() -> int: - """Provides an current timestamp with reduced resolution, to improve anonymity.""" - granularity = 2**20 # about 12 days - return int(time.time()) // granularity * granularity +def month_timestamp() -> int: + """Provides the timestamp of the current month's beginning (for improved privacy)""" + return timegm(date.today().replace(day=1).timetuple()) app.mount("/", StaticFiles(directory="static", html=True), name="static") diff --git a/static/form.js b/static/form.js index ec00949..b69f358 100644 --- a/static/form.js +++ b/static/form.js @@ -176,5 +176,6 @@ function formCoordsToMap() { function formatTimestamp(ts) { const date = new Date(ts * 1000); - return date.toLocaleDateString(); + // using Swedish format as a hack to get an iso formatted date + return date.toLocaleDateString("sv", {timeZone: "UTC"}).replace(/\-\d+$/,'') }