diff --git a/src/Model/BoundaryCondition/BoundaryCondition.py b/src/Model/BoundaryCondition/BoundaryCondition.py index ba23cb7d09d2d3cf79e04a996f6c53a36df88071..918af8b38bb7548c4970fb460964ae3e47197423 100644 --- a/src/Model/BoundaryCondition/BoundaryCondition.py +++ b/src/Model/BoundaryCondition/BoundaryCondition.py @@ -18,7 +18,12 @@ import logging -from tools import trace, timer, old_pamhyr_date_to_timestamp +from tools import ( + trace, timer, + old_pamhyr_date_to_timestamp, + date_iso_to_timestamp, + date_dmy_to_timestamp, +) from Model.Tools.PamhyrDB import SQLSubModel from Model.Except import NotImplementedMethodeError @@ -189,6 +194,10 @@ class BoundaryCondition(SQLSubModel): @classmethod def time_convert(cls, data): if type(data) is str: + if data.count("-") == 2: + return date_iso_to_timestamp(data) + if data.count("/") == 2: + return date_dmy_to_timestamp(data) if data.count(":") == 3: return old_pamhyr_date_to_timestamp(data) if data.count(":") == 2: diff --git a/src/View/Tools/ASubWindow.py b/src/View/Tools/ASubWindow.py index 7dc57b0d39414ba6581a307a90bbf37c8d63758a..e568aa25cc5dd17035056ad591178df3d607bc35 100644 --- a/src/View/Tools/ASubWindow.py +++ b/src/View/Tools/ASubWindow.py @@ -68,11 +68,11 @@ class WindowToolKit(object): header = [] values = [] - delimiter = '\t' + delimiter = ' ' if ';' in data: delimiter = ';' - if ' ' in data: - delimiter = ' ' + if '\t' in data: + delimiter = '\t' stream = StringIO(data) rows = csv.reader(stream, delimiter=delimiter) diff --git a/src/tools.py b/src/tools.py index b8a4c0b3258ac08672318244108fdd8e90cf53d7..35ed7b40dffad76497c92e4df2a0b261062ad283 100644 --- a/src/tools.py +++ b/src/tools.py @@ -234,6 +234,22 @@ def timestamp(dt: datetime): return (dt - datetime(1970, 1, 1)).total_seconds() return dt.timestamp() +def date_iso_to_timestamp(date: str): + return datetime.isoformat(date) + +def date_dmy_to_timestamp(date: str): + if date.count(":") == 0: + ret = datetime.strptime(date, "%d/%m/%y") + elif date.count(".") == 1: + ret= datetime.strptime(date, "%d/%m/%y %H:%M:%S.%f") + elif date.count(":") == 1: + ret = datetime.strptime(date, "%d/%m/%y %H:%M") + elif date.count(":") == 2: + ret = datetime.strptime(date, "%d/%m/%y %H:%M:%S") + else: + ret = datetime.now() + + return ret.timestamp() def old_pamhyr_date_to_timestamp(date: str): v = date.split(":")