Skip to content

Commit 97e550b

Browse files
committed
Robustly handle timestamps
1 parent 2e0ba43 commit 97e550b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

app/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ async def version(
113113
"""
114114
background_tasks.add_task(
115115
_log_visit,
116-
timestamp=datetime.datetime.now().isoformat(),
116+
timestamp=datetime.datetime.now().isoformat(timespec="microseconds"),
117117
version_multiqc=version_multiqc,
118118
version_python=version_python,
119119
operating_system=operating_system,
@@ -240,7 +240,7 @@ def _summarize_visits(interval="5min") -> Response:
240240
dtype="string",
241241
na_filter=False, # prevent empty strings from converting to nan or <NA>
242242
)
243-
df["start"] = pd.to_datetime(df["timestamp"])
243+
df["start"] = pd.to_datetime(df["timestamp"], format="%Y-%m-%dT%H:%M:%S.%f", errors="coerce")
244244
df["end"] = df["start"] + pd.to_timedelta(interval)
245245
df["start"] = df["start"].dt.strftime("%Y-%m-%d %H:%M")
246246
df["end"] = df["end"].dt.strftime("%Y-%m-%d %H:%M")

0 commit comments

Comments
 (0)