Data-Test-Executer Framework speziell zum Test von Datenverarbeitungen mit Datengenerierung, Systemvorbereitungen, Einspielungen, ganzheitlicher diversifizierender Vergleich
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

105 lines
3.6 KiB

# functions related to Date-fields
# -----------------------------------------------------
"""
additionally functions for calculating date with formulas like [DATE+2M] and for comparison of date related on two reference-dates
"""
import datetime
#from dateutil.relativedelta import relativedelta
import re
import utils.data_const as D
F_DIR = "%Y-%m-%d_%H-%M-%S"
F_DE = "%d.%m.%Y"
def getActdate(format):
return getFormatdate(datetime.datetime.now(), format)
def getFormatdate(date, format):
""" it return the date as string in the format """
return date.strftime(format)
def parseFormula(instring):
instring = instring.upper()
if instring[2:6] == "DATE":
refdate = datetime.datetime.today()
formula = instring[7:-2].upper()
else:
dstring = instring[2:instring.find(" ")]
res = parseDate(dstring)
refdate = datetime.datetime(res[0], res[1], res[2], res[3], res[4], res[5])
formula = instring[2+len(dstring):-2]
formula = re.sub(r' ', '', formula)
year = refdate.year
mon = refdate.month
day = refdate.day
hour = refdate.hour
min = refdate.minute
sec = refdate.second
if re.match(r"[-+]\d+[JYMDT]", formula):
ress = re.compile(r"([-+])(\d+)([JYMDT])")
for res in ress.finditer(formula):
summand = int(res.group(2))
if res.group(1) == "-":
summand = summand * (-1)
if res.group(3) in "JY":
year = year + summand
if res.group(3) in "M":
mon = mon + summand
while mon <= 0:
mon = mon + 12
year = year - 1
while mon > 12:
mon = mon - 12
year = year + 1
if res.group(3) in "DT":
refdate = datetime.datetime(year, mon, day, hour, min, sec)
refdate = refdate + datetime.timedelta(days=summand)
year = refdate.year
mon = refdate.month
day = refdate.day
hour = refdate.hour
min = refdate.minute
sec = refdate.second
return (year, mon, day, hour, min, sec)
else:
print("re matcht nicht")
return (year, mon, day, hour, min, sec)
def parseDate(instring):
year = 0
mon = 0
day = 0
hour = 0
min = 0
sec = 0
if instring[0:2] == "{(" and instring[-2:] == ")}":
return parseFormula(instring)
for d in ["_", " "]:
if d in instring and instring.find(d) > 8:
dstring = instring[0:instring.find(d)]
tstring = instring[instring.find(d)+1:]
dres = parseDate(dstring)
tres = parseDate(tstring)
return (dres[0], dres[1], dres[2], tres[3], tres[4], tres[5])
if re.match(r"\d{4}[-./]\d{2}[-./]\d{2}", instring):
res = re.match(r"(\d{4})[-./](\d{2})[-./](\d{2})", instring)
year = int(res.group(1))
mon = int(res.group(2))
day = int(res.group(3))
return (year, mon, day, hour, min, sec)
if re.match(r"\d{1,2}[-./]\d{1,2}[-./]\d{1,2}", instring):
res = re.match(r"(\d{1,2})[-./](\d{1,2})[-./](\d{4})", instring)
year = int(res.group(3))
mon = int(res.group(2))
day = int(res.group(1))
return (year, mon, day, hour, min, sec)
if re.match(r"\d{2}[-:]\d{2}[-:/]\d{2}", instring):
res = re.match(r"(\d{2})[-:/](\d{2})[-:/](\d{2})", instring)
hour = int(res.group(1))
min = int(res.group(2))
sec = int(res.group(3))
return (year, mon, day, hour, min, sec)