Reputation: 199
I get the TypeError: relativedelta only diffs datetime/date after execute code
This is my robot code:
Test calculate age
[Tags] Test
${cal} AgeTest 1988, 10, 1
This is my python code:
from datetime import date
from dateutil.relativedelta import relativedelta
def AgeTest(dob):
age = relativedelta(date.today(), dob)
print (age)
return age.years, age.months, age.days
How to fix it.
Upvotes: 0
Views: 6053
Reputation: 1709
The datatype of dob you're passing is String
but in python is need tuple
So you need to convert your string to tuple
first,
Just Change following below
def AgeTest(dob):
dobnew = tuple(map(int, dob.split(',')))
age = relativedelta(date.today(), date(*dobnew))
return age.years, age.months, age.days
Upvotes: 3
Reputation: 1304
I haven't worked with Robot Framework, but it looks to me as it did not recognize your input as a proper date; looking at docs, possibly formatting it as 1988-10-1
could help. On the other hand, if dob
is a tuple, you could make it to a date
object easily:
age = relativedelta(date.today(), date(*dob))
Upvotes: 2