Skip to content

Commit

Permalink
add @mandresm contributions to the fix
Browse files Browse the repository at this point in the history
(cherry picked from commit 6a345ae)
  • Loading branch information
mandresm committed Jan 24, 2025
1 parent 684cf0f commit 5daa7a9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/esm_parser/esm_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2338,12 +2338,14 @@ def do_math_in_entry(tree, rhs, config):
if "${" in str(entry):
return entry
entry = " " + str(entry) + " "
date_operation = False
while "$((" in entry:
math, after_math = entry.split("))", 1)
math, before_math = math[::-1].split("(($", 1)
math = math[::-1]
before_math = before_math[::-1]
if DATE_MARKER in math:
date_operation = True
all_dates = []
steps = math.split(" ")
steps = [step for step in steps if step]
Expand Down Expand Up @@ -2421,14 +2423,18 @@ def do_math_in_entry(tree, rhs, config):
math = math + "all_dates[" + str(index) + "]"
index += 1
result = eval(math)
if keep_list:
return ListWithProvenance(result, [])
if isinstance(result, list):
if isinstance(result, list) and date_operation:
result = result[
-1
] # should be extended in the future - here: if list (= if diff between dates) than result in seconds
elif isinstance(result, list):
entry = ListWithProvenance(result, None)
entry.set_provenance(rhs.provenance)
return entry

result = str(result)
entry = before_math + result + after_math

# TODO MA: this is a provisional dirty fix for release. Get rid of this once a more
# general solution is worked out
# ORIGINAL LINE: return convert(entry.strip())
Expand Down

0 comments on commit 5daa7a9

Please sign in to comment.