mirror of https://gitlab.com/pamhyr/pamhyr2
BC: Add DMY datetime support.
parent
de1f5c1944
commit
a834e1905d
|
|
@ -18,7 +18,12 @@
|
||||||
|
|
||||||
import logging
|
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.Tools.PamhyrDB import SQLSubModel
|
||||||
from Model.Except import NotImplementedMethodeError
|
from Model.Except import NotImplementedMethodeError
|
||||||
|
|
@ -189,6 +194,10 @@ class BoundaryCondition(SQLSubModel):
|
||||||
@classmethod
|
@classmethod
|
||||||
def time_convert(cls, data):
|
def time_convert(cls, data):
|
||||||
if type(data) is str:
|
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:
|
if data.count(":") == 3:
|
||||||
return old_pamhyr_date_to_timestamp(data)
|
return old_pamhyr_date_to_timestamp(data)
|
||||||
if data.count(":") == 2:
|
if data.count(":") == 2:
|
||||||
|
|
|
||||||
|
|
@ -68,11 +68,11 @@ class WindowToolKit(object):
|
||||||
header = []
|
header = []
|
||||||
values = []
|
values = []
|
||||||
|
|
||||||
delimiter = '\t'
|
delimiter = ' '
|
||||||
if ';' in data:
|
if ';' in data:
|
||||||
delimiter = ';'
|
delimiter = ';'
|
||||||
if ' ' in data:
|
if '\t' in data:
|
||||||
delimiter = ' '
|
delimiter = '\t'
|
||||||
|
|
||||||
stream = StringIO(data)
|
stream = StringIO(data)
|
||||||
rows = csv.reader(stream, delimiter=delimiter)
|
rows = csv.reader(stream, delimiter=delimiter)
|
||||||
|
|
|
||||||
16
src/tools.py
16
src/tools.py
|
|
@ -234,6 +234,22 @@ def timestamp(dt: datetime):
|
||||||
return (dt - datetime(1970, 1, 1)).total_seconds()
|
return (dt - datetime(1970, 1, 1)).total_seconds()
|
||||||
return dt.timestamp()
|
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):
|
def old_pamhyr_date_to_timestamp(date: str):
|
||||||
v = date.split(":")
|
v = date.split(":")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue