From 621db6ad2c1064f8e9df015def60a9c9911fefe2 Mon Sep 17 00:00:00 2001 From: jomo Date: Thu, 1 Feb 2024 00:03:33 +0100 Subject: [PATCH] use current month for last_updated value --- main.py | 12 ++++++------ static/form.js | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) 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+$/,'') }