From 0ae4902a7e6faf3d7c63fecfdb4c4780a40d29d1 Mon Sep 17 00:00:00 2001 From: Baudouin Raoult Date: Thu, 21 Mar 2024 09:11:08 +0000 Subject: [PATCH] Fix dates as strings --- ecml_tools/data/misc.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ecml_tools/data/misc.py b/ecml_tools/data/misc.py index 17b5f11..6f4a83a 100644 --- a/ecml_tools/data/misc.py +++ b/ecml_tools/data/misc.py @@ -97,6 +97,13 @@ def _as_date(d, dates, last): return np.datetime64(f"{year:04}-{month:02}-{day:02}T00:00:00") if isinstance(d, str): + + if "-" in d and ":" in d: + date, time = d.replace(" ", "T").split("T") + year, month, day = date.split("-") + hour, minute, second = time.split(":") + return np.datetime64(f"{year:04}-{month:02}-{day:02}T{hour}:{minute}:{second}") + if "-" in d: assert ":" not in d bits = d.split("-")