You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DateTime: Conversion to timedelta fails with bad error message if values are too large #5834
For example, Convert Time 1e14 timedelta fails with this error:
OverflowError: days=1157407407; must have magnitude <= 999999999
Using even larger values like 1e15 changes the error to this:
OverflowError: Python int too large to convert to C int
The root cause is that timedelta requires values to be between 999999999 and 999999999 days. The first error is somewhat helpful, but the latter is rather useless. We can easily make the situation better by catching the OverflowError and raising a ValueError with a better message. I have a fix ready locally that changes the first error to this:
ValueError: 1157407407 days 9 hours 46 minutes 40 seconds cannot be represented as a timedelta object. Values must be between -999999999 and 999999999 days.
This is a spinoff from issue #5819 and PR #5820. As the discussion explains, argument conversion uses DateTime internally for datetime, date and timedelta conversion and the resulting OverflowError currently causes problems also there. Those problems will be fixed as part of the aforementioned issue and PR, but it still makes sense to enhance DateTime to produce better error messages.
As discussed in #5820, here are some ideas for this issue: related cases that still fail with bad errors. I collected and tested them with the help of Claude Code, using the current master and Python 3.13 on Linux. I haven't looked into possible fixes yet, so please take this as a starting point rather than a complete analysis.
Infinite and NaN values: Convert Time inf result_format=timedelta fails with OverflowError: cannot convert float infinity to integer. timedelta(seconds=inf) raises OverflowError, and secs_to_timestr(inf) in the new except block raises it again. The verbose, compact and timer formats fail the same way, and so does exclude_millis=yes even with the default number format, because the value is rounded. -inf and values that are too large for a float, like 1e400 or 1e308 days, fail the same way, because they are infinite too. nan fails with ValueError: cannot convert float NaN to integer.
Too large integers: Convert Time ${{10**400}} fails with OverflowError: int too large to convert to float in timestr_to_secs.
Time.timedelta: Add Time To Date 2024-01-01 1e20 and Get Current Date increment=1e20 fail with OverflowError: Python int too large to convert to C int. Date calculations use the Time.timedelta property, which creates the timedelta without the new handling.
Dates out of range: Add Time To Date 2024-01-01 1e7 days, Subtract Time From Date 0001-01-01 1 day and Get Current Date increment=1e7 days fail with OverflowError: date value out of range. Here, the timedelta itself is fine, but the result is out of range. Rounding can also go out of range: Convert Date 9999-12-31 23:59:59.9999 exclude_millis=yes fails the same way.
Epoch seconds as input: Convert Date ${1e20} fails with OverflowError: timestamp out of range for platform time_t, and Convert Date ${1e18} with OSError: [Errno 75] Value too large for defined data type. Both come from datetime.fromtimestamp in Date._epoch_seconds_to_datetime, so the limits and errors depend on the platform. Convert Date ${3e11} already fails with ValueError: year 11476 is out of range. BuiltIn's Get Time year ${1e20} has the same problem in robot.utils.robottime.get_time.
Epoch seconds as output: Convert Date 0001-01-01 result_format=epoch fails with ValueError: year 0 is out of range. It is a ValueError, but the year in the message isn't the one in the input. Convert Date 9999-12-31 23:59:59 result_format=epoch fails with ValueError: year 10000 is out of range depending on the time zone. It fails with CET, but works with UTC.
Some of these may not be worth fixing. For example, the epoch output cases in 6 already fail with ValueError, and only the message is misleading. With #5820, argument conversion reports all of these as normal conversion errors when it uses DateTime for timedelta, datetime and date. The keywords themselves still fail with the errors above.
This issue is already closed with the v7.5.1 milestone. Should these cases still go into 7.5.1, or later? And should they be fixed as part of this issue or get a separate one?
I don't think any of the new items are severe enough that they must be in RF 7.5.1 that's already overdo. That said, cases where the error is really misleading could still be fixed. I can take a look at these later, but you can @d-biehl do that as well.
For most parts the fixes should got to robot.utils.robottime and many of them are related to inf and nan. Fixes that go to RF 7.5.1 should only change cases where execution would anyway fail like elapsed_time_to_string(float('inf')). Changing functions that currently can return inf or nan to raise could cause backwards incompatibility issues. I think that would be fine in RF 7.6, but not in a bug fix release.
I looked at some of these and it turned out that it would be much easier if we could just fail inf and nan in input. That would, however, be potentially backwards incompatible change so it's not a good idea now. I already changed secs_to_timestr and elapsed_time_to_string to raise ValueError with inf/NaN input and consider that safe, because there functions already failed but for OverflowError. I'll commit these changes along with related unit tests and updated DateTime tests, but otherwise I won't be making changes now.
Do you @d-biehl see places where we could make safe changes now and do you have time and interest to make such changes?
I'll anyway submit a separate issue about enhancing handling of inf/NaN and large numbers in DateTime in RF 7.6.
Activity
DateTime: Better error if timedelta value is too large
Update tests after DateTime fix
d-biehl commentedon Oct 29, 2026
As discussed in #5820, here are some ideas for this issue: related cases that still fail with bad errors. I collected and tested them with the help of Claude Code, using the current master and Python 3.13 on Linux. I haven't looked into possible fixes yet, so please take this as a starting point rather than a complete analysis.
Convert Time inf result_format=timedeltafails withOverflowError: cannot convert float infinity to integer.timedelta(seconds=inf)raisesOverflowError, andsecs_to_timestr(inf)in the newexceptblock raises it again. Theverbose,compactandtimerformats fail the same way, and so doesexclude_millis=yeseven with the defaultnumberformat, because the value is rounded.-infand values that are too large for a float, like1e400or1e308 days, fail the same way, because they are infinite too.nanfails withValueError: cannot convert float NaN to integer.Convert Time ${{10**400}}fails withOverflowError: int too large to convert to floatintimestr_to_secs.Time.timedelta:Add Time To Date 2024-01-01 1e20andGet Current Date increment=1e20fail withOverflowError: Python int too large to convert to C int. Date calculations use theTime.timedeltaproperty, which creates thetimedeltawithout the new handling.Add Time To Date 2024-01-01 1e7 days,Subtract Time From Date 0001-01-01 1 dayandGet Current Date increment=1e7 daysfail withOverflowError: date value out of range. Here, thetimedeltaitself is fine, but the result is out of range. Rounding can also go out of range:Convert Date 9999-12-31 23:59:59.9999 exclude_millis=yesfails the same way.Convert Date ${1e20}fails withOverflowError: timestamp out of range for platform time_t, andConvert Date ${1e18}withOSError: [Errno 75] Value too large for defined data type. Both come fromdatetime.fromtimestampinDate._epoch_seconds_to_datetime, so the limits and errors depend on the platform.Convert Date ${3e11}already fails withValueError: year 11476 is out of range. BuiltIn'sGet Time year ${1e20}has the same problem inrobot.utils.robottime.get_time.Convert Date 0001-01-01 result_format=epochfails withValueError: year 0 is out of range. It is aValueError, but the year in the message isn't the one in the input.Convert Date 9999-12-31 23:59:59 result_format=epochfails withValueError: year 10000 is out of rangedepending on the time zone. It fails with CET, but works with UTC.Some of these may not be worth fixing. For example, the epoch output cases in 6 already fail with
ValueError, and only the message is misleading. With #5820, argument conversion reports all of these as normal conversion errors when it usesDateTimefortimedelta,datetimeanddate. The keywords themselves still fail with the errors above.d-biehl commentedon Oct 29, 2026
This issue is already closed with the v7.5.1 milestone. Should these cases still go into 7.5.1, or later? And should they be fixed as part of this issue or get a separate one?
pekkaklarck commentedon Oct 30, 2026
I don't think any of the new items are severe enough that they must be in RF 7.5.1 that's already overdo. That said, cases where the error is really misleading could still be fixed. I can take a look at these later, but you can @d-biehl do that as well.
pekkaklarck commentedon Oct 30, 2026
For most parts the fixes should got to
robot.utils.robottimeand many of them are related toinfandnan. Fixes that go to RF 7.5.1 should only change cases where execution would anyway fail likeelapsed_time_to_string(float('inf')). Changing functions that currently can returninfornanto raise could cause backwards incompatibility issues. I think that would be fine in RF 7.6, but not in a bug fix release.pekkaklarck commentedon Oct 30, 2026
I looked at some of these and it turned out that it would be much easier if we could just fail
infandnanin input. That would, however, be potentially backwards incompatible change so it's not a good idea now. I already changedsecs_to_timestrandelapsed_time_to_stringto raise ValueError with inf/NaN input and consider that safe, because there functions already failed but for OverflowError. I'll commit these changes along with related unit tests and updated DateTime tests, but otherwise I won't be making changes now.Do you @d-biehl see places where we could make safe changes now and do you have time and interest to make such changes?
I'll anyway submit a separate issue about enhancing handling of inf/NaN and large numbers in DateTime in RF 7.6.
Reject inf/nan in secs_to_timestr and elapsed_time_to_string