Skip to content

Commit 950a197

Browse files
author
Tareq
committed
fixed the format change feature
1 parent 9de324f commit 950a197

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

Framework/Built_In_Automation/Sequential_Actions/common_functions.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4049,7 +4049,8 @@ def modify_datetime(data_set):
40494049

40504050
data = None
40514051
var_name = None
4052-
date_format = None
4052+
current_format = None
4053+
target_format = None
40534054

40544055
fields = ["years", "months", "days", "hours", "minutes", "seconds"]
40554056

@@ -4095,12 +4096,17 @@ def perform_mod(op, val, t):
40954096
return t
40964097

40974098
for left,mid,right in data_set:
4098-
if "format" in left:
4099-
date_format = right
4099+
if "current format" == left.lower():
4100+
current_format = right
4101+
if "target format" == left.lower():
4102+
target_format = right
41004103

4101-
if date_format:
4104+
if current_format:
41024105
if os.name == "nt":
4103-
date_format = date_format.replace("%-d", "%#d").replace("%-m", "%#m").replace("%-H", "%#H").replace("%-I", "%#I").replace("%-M", "%#M").replace("%-S", "%#S").replace("%-j", "%#j")
4106+
current_format = current_format.replace("%-d", "%#d").replace("%-m", "%#m").replace("%-H", "%#H").replace("%-I", "%#I").replace("%-M", "%#M").replace("%-S", "%#S").replace("%-j", "%#j")
4107+
else:
4108+
CommonUtil.ExecLog(sModuleInfo, "current format parameter is not provided",3)
4109+
return CommonUtil.Exception_Handler(sys.exc_info())
41044110

41054111
for left, mid, right in data_set:
41064112
left = left.strip().lower()
@@ -4110,9 +4116,9 @@ def perform_mod(op, val, t):
41104116
elif right.strip().lower() in ("monday","tuesday","wednesday","thursday","friday","saturday","sunday"):
41114117
data = parser.parse(right.strip())
41124118
else:
4113-
if date_format:
4114-
_date_format = date_format.replace("%-","%").replace("%#","%")
4115-
data = datetime.strptime(right.strip(),_date_format)
4119+
if current_format:
4120+
_current_format = current_format.replace("%-","%").replace("%#","%")
4121+
data = datetime.strptime(right.strip(),_current_format)
41164122
else:
41174123
data = parser.parse(right.strip())
41184124
continue
@@ -4124,10 +4130,11 @@ def perform_mod(op, val, t):
41244130
if left in fields:
41254131
data = perform_mod(left, right, data)
41264132

4127-
if date_format:
4128-
data = data.strftime(date_format)
4133+
if target_format:
4134+
# Convert the datetime object to a new format string
4135+
data = data.strftime(target_format)
41294136
else:
4130-
data = str(data)
4137+
data = data.strftime(_current_format)
41314138

41324139
CommonUtil.ExecLog(sModuleInfo, "Modified datetime. New value: %s" % data, 1)
41334140
return sr.Set_Shared_Variables(var_name, data)

0 commit comments

Comments
 (0)