From efe88af80cfe0c90fdd8fe0317dbaeba91abf523 Mon Sep 17 00:00:00 2001
From: Romin <15949-romin.benfer@users.noreply.git.rwth-aachen.de>
Date: Mon, 10 Jul 2023 20:55:52 +0200
Subject: [PATCH] Fixed datetime format

---
 src/coscine/__about__.py |  2 +-
 src/coscine/form.py      | 23 +++++++++++++++++------
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/coscine/__about__.py b/src/coscine/__about__.py
index 50b59a2..a970547 100644
--- a/src/coscine/__about__.py
+++ b/src/coscine/__about__.py
@@ -30,7 +30,7 @@ __title__ = "coscine"
 
 # Current package version
 # Do not set version to 1.0.0 before update to Coscine API version 2
-__version__ = "0.9.3"
+__version__ = "0.9.4"
 
 # Short package description
 __summary__ = (
diff --git a/src/coscine/form.py b/src/coscine/form.py
index f759aee..87ec186 100644
--- a/src/coscine/form.py
+++ b/src/coscine/form.py
@@ -580,21 +580,29 @@ class InputForm:
 
 ###############################################################################
 
+    def xsd_type(self, key: str) -> str:
+        """
+        Returns the xsd type identifier for a given field.
+        """
+        datatype = self.properties(key).datatype
+        if datatype and datatype.startswith("http:"):
+            datatype = f"xsd:{urllib.parse.urlparse(datatype)[-1]}"
+        return datatype
+
 ###############################################################################
 
     def datatype(self, key: str) -> type:
         """
         Returns the datatype for a given field (which may be None).
         """
-        datatype = self.properties(key).datatype
-        if datatype and datatype.startswith("http:"):
-            datatype = f"xsd:{urllib.parse.urlparse(datatype)[-1]}"
         if self.is_controlled(key):
             return str
-        return self._xsd_typeof(datatype)
+        else:
+            datatype: str = self.xsd_type(key)
+            return self._xsd_typeof(datatype)
 
 ###############################################################################
-
+# FIXME: Lots of xsd types still unhandled, especially datetime formats
     def type_format(self, key: str) -> str:
         """
         Returns the format for a datatype of a field.
@@ -608,7 +616,10 @@ class InputForm:
         if datatype == float:
             return "%f"
         if datatype == datetime:
-            return "%Y-%m-%d"
+            if self.xsd_type(key) == "xsd:dateTime":
+                return "%Y-%m-%dT%H:%M:%S"
+            else:
+                return "%Y-%m-%d"
         return "Invalid Format"
 
 ###############################################################################
-- 
GitLab