[Bug]: keep.add_time_to_date silently returns the input date when it cannot read the time string
add_time_to_date pulls units out with re.findall(r"(\d+)([wdhms])", time_str) and adds
whatever it found. When it finds nothing it adds nothing and returns the date it was given,
so a string it does not understand behaves exactly like "add zero".
from keep.functions import add_time_to_date
d, f = "2024-07-01", "%Y-%m-%d"
add_time_to_date(d, f, "2d") # 2024-07-03
add_time_to_date(d, f, "1y") # 2024-07-01 unchanged
add_time_to_date(d, f, "3M") # 2024-07-01 unchanged
add_time_to_date(d, f, "10") # 2024-07-01 unchanged
add_time_to_date(d, f, "2 d") # 2024-07-01 unchanged
add_time_to_date(d, f, "") # 2024-07-01 unchangedYears and months are the ones I would expect people to reach for, and neither is a
supported unit. A workflow computing an SLA deadline or a snooze window from 1y gets the
start date back and nothing anywhere says the input was not understood, so the workflow
looks like it worked.
m already means minutes, so 3M cannot be added as months without making the unit
ambiguous. This is only about the silence, not about supporting more units.
Expected: a time string with no readable unit raises, the way an unreadable value does
elsewhere in this module. Everything the regex accepts today keeps working, spaces
included: 1w, 2d, 3h, 30m, 45s, 1w 2d 3h 30m.
I have a fix and tests.
Source: keephq/keep